[英]Comma separated step for number input box
I can specify the 'step' for thousand increments when a user inputs a number. 当用户输入数字时,我可以以千为增量指定“步长”。 But why I cannot write '1,000' instead of '1000' for the increment to happen with the comma separation for thousands?
但是,为什么我不能写“ 1,000”而不是“ 1000”,以使成千上万的逗号分隔出现增量? How to do this?
这个怎么做?
<div class="input"><label for="salary">Salary</label> <input class='inp_cont' id="salary" name="salary" placeholder="Enter your salary" step="1000" min="0" required="" type="number"></div>
It cannot be done if you want to stick to the type="number"
, because: 如果您要坚持
type="number"
,则无法完成此操作,因为:
As Chrome reports: 根据Chrome的报告:
The value must match to the following regular expression: -?(\\d+|\\d+.\\d+|.\\d+)([eE][-+]?\\d+)?
该值必须与以下正则表达式匹配:-?(\\ d + | \\ d +。\\ d + |。\\ d +)([eE] [-+]?\\ d +)?
As specification mentions: 如规范所述:
value = floating-point number
值= 浮点数
Follow the above link to see that spec doesn't mention use of comma at all. 单击上面的链接,可以看到规范根本没有提到逗号的使用。
If you want to switch to type="text"
: 如果要切换到
type="text"
:
document.getElementById('salary').addEventListener('input', event => event.target.value = (parseInt(event.target.value.replace(/[^\\d]+/gi, '')) || 0).toLocaleString('en-US') );
<div class="input"> <label for="salary">Salary</label> <input class='inp_cont' id="salary" pattern="^[\\d,]+$" name="salary" placeholder="Enter your salary" required="" type="text"> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.