考虑以下 MWE:
<!DOCTYPE html>
<html>
<head>
<title>Progress test</title>
</head>
<body>
<progress id="progress"></progress>
<script>
progress.max = 10000000000;
progress.value = 10000000000 / 2;
</script>
</body>
</html>
这曾经适用于 Internet Explorer、Mozilla Firefox、Google Chrome 和 Opera。但今天我意识到它不再适用于 Google Chrome;显然,值 10000000000 和 10000000000/2 太大了。
这让我想知道官方规范对此有何说明。他们是否保证这么大的数字应该有效(在这种情况下,Google Chrome 中有一个错误),或者我的数字是否高于保证有效的最大值(在这种情况下,我很幸运它可以在 IE 中工作)和FF)?
最佳答案
HTML5 specification关于 progress element 说:
The value and max attributes, when present, must have values that are valid floating-point numbers.
一个floating-point number定义为:
A string is a valid floating-point number if it consists of:
Optionally, a "-" (U+002D) character. One or both of the following, in the given order: A series of one or more ASCII digits. A single "." (U+002E) character. A series of one or more ASCII digits. Optionally: Either a "e" (U+0065) character or a "E" (U+0045) character. Optionally, a "-" (U+002D) character or "+" (U+002B) character. A series of one or more ASCII digits.
后来又说解析 float 的算法应该从IEEE 754 double float 集合中选择一个值。
根据问题:
biggest integer that can be stored in a double
IEEE 754 double 的最大值约为 1.8 × 10^308。因此,您的数字 10000000000
很大程度上足够小,可以用 IEEE 754 double 表示,并且应该可以由任何有效的 HTML5 浏览器正确解释。
关于javascript - HTML5 进度最大值和值范围 : too large values?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30990808/