我注意到尽管 docs如果没有值传递给该方法,stepUp()
会使用 step
属性来增加输入值。在最新的 Chrome、Opera、Firefox 上进行了测试。以下示例警报 3.15
。
var input = document.getElementById('pi');
input.stepUp();
alert(input.value);
<input type="number" step="0.01" value="3.14" id="pi">
这是一个未记录的功能吗?
最佳答案
我认为你应该引用W3C Recommendation而不是 w3schools。在您发布的链接上,尚不清楚 number
在stepUp(number)
是可选的,如果不存在则设置为 1(向下滚动到 DOM 界面)。
void stepUp(optional long n = 1);
此外还不清楚 number
必须一步步相乘才能得到最终的delta
。 (ref)
6.[...] Otherwise (value subtracted from the step base is an integral multiple of the allowed value step), run the following substeps:
- Let n be the argument.
- Let delta be the allowed value step multiplied by n.
- If the method invoked was the stepDown() method, negate delta.
- Let value be the result of adding delta to value.
在你的例子中,从number
开始在stepUp(number)
不存在,默认采用 1 并乘以步长 0.1 得到 delta
关于javascript - stepUp 方法逐步增加值,而不是 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38695096/