HTMLProgressElement: max 属性

Baseline 已广泛支持

此特性已相当成熟,可在许多设备和浏览器版本上使用。自 ⁨2015 年 7 月⁩以来,各浏览器均已提供此特性。

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

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

示例

HTML

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

JavaScript

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

console.log(`Default value of 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);

规范

规范
HTML
# dom-progress-max

浏览器兼容性