更改 HTML 数字输入的增量值 - 小数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26003148/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change the Increment Value of HTML Number Input - Decimals
提问by Ryan
Is there any way to change how much a number is incremented when using the up/down arrows on a HTML number input form?
在 HTML 数字输入表单上使用向上/向下箭头时,是否有任何方法可以更改数字的增量?
<input type="number" step="any" value="0.00000000"></input>
I'm working with tiny numbers, it would be nice if the up/down arrows incremented just 0.00000001 at a time, instead of a whole number.
我正在处理很小的数字,如果向上/向下箭头一次只增加 0.00000001,而不是一个整数,那就太好了。
- 0.00000000
- 0.00000001
- 0.00000002
- 0.00000003
- 0.00000000
- 0.00000001
- 0.00000002
- 0.00000003
Instead of
代替
- 0.00000000
- 1
- 2
- 3
- 0.00000000
- 1
- 2
- 3
I doubt very much if there is an easy way to do this, just though I'd ask and see if anyone else has a workaround or method as I'm sure many people experience a similar issue.
我非常怀疑是否有一种简单的方法可以做到这一点,尽管我会询问并看看其他人是否有解决方法或方法,因为我相信很多人都遇到过类似的问题。
Thanks,
谢谢,
回答by Jukka K. Korpela
The step
attributeis for this. Your code now has the value any
, which means that any values are accepted and the step size is the default, 1. Replace it by a specific number to set the granularity and the step size. Example:
该step
属性是这个。您的代码现在具有值any
,这意味着接受任何值并且步长为默认值,1。将其替换为特定数字以设置粒度和步长。例子:
<input type="number" step="0.00000001" value="0.00000000">
Note: The end tag </input>
is invalid in HTML syntax for HTML5. In XHTML syntax it is allowed, but “self-closing tags” are recommended instead of it, e.g. <input type="number" step="0.00000001" value="0.00000000" />
.
注意:结束标记</input>
在 HTML5 的 HTML 语法中无效。在 XHTML 语法中它是允许的,但建议使用“自闭合标签”代替它,例如<input type="number" step="0.00000001" value="0.00000000" />
.