javascript - HTML5 进度最大值和值范围 : too large values?

标签 javascript html numbers progress-bar specifications

考虑以下 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/

相关文章:

php - 如果缺少数字,则将数字向下移动 mysql

javascript - 如何在 keyup 事件上使用 Jquery 获取动态生成的表的单元格的行索引号?

JavaScript:使用条件语句进行解构

jquery - 单击事件被触发两次 - jquery

css - 如何在文本区域内默认包含图标

php - 如何将百分比(例如 25%)简化为简单的陈述(例如 4 中的 1)?

numbers - 马克西玛。如何防止学位计算

php - 为什么输入的[]没有提交?

javascript - 如何在没有 ReactDOM 的情况下检测 React 组件的溢出?

javascript - checkValidity 函数未检测到类型 "tel"的无效输入