1. 面向开发者的 Web 技术
  2. Web API
  3. HTMLProgressElement
  4. HTMLProgressElement:max 属性

此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

HTMLProgressElement:max 属性

基线 广泛可用

自 2015年7月 起,此特性已在主流浏览器中得到支持,可在大多数设备和浏览器版本中正常使用。

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);

规范

规范
HTML
# dom-progress-max

浏览器兼容性

帮助改进 MDN

了解如何参与贡献

此页面最后更新于 ,由 MDN 贡献者更新。

AltStyle によって変換されたページ (->オリジナル) /