HTMLProgressElement:position 属性

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 接口的 position 只读属性返回 <progress> 元素的当前进度。

对于确定的进度条返回当前值除以最大值的结果,也就是说,它是介于 0.01.0 之间的分数。

对于不确定的进度条该值总是 -1

示例

HTML

html
确定的进度条:<progress id="pBar"></progress>位置: <span>0</span>

JavaScript

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

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

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

  span.textContent = pBar.position;
}, 100);

规范

Specification
HTML
# dom-progress-position-dev

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
position

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support