HTMLProgressElement:max 属性

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

HTMLProgressElement 接口的 max 属性表示 <progress> 元素的范围的上限。

一个大于零的浮点数。默认值是 1.0。

示例

HTML

html
进度:<progress id="pBar"></progress> <span>0</span>%

JavaScript

js
const pBar = document.getElementById("pBar");
const span = document.getElementsByTagName("span")[0];

console.log(`max 的默认值:${pBar.max}`);

pBar.max = 100;
pBar.value = 0;

setInterval(() => {
  pBar.value = pBar.value < pBar.max ? pBar.value + 1 : 0;

  span.textContent = Math.trunc(pBar.position * 100);
}, 100);

规范

Specification
HTML Standard
# dom-progress-max

浏览器兼容性

BCD tables only load in the browser