类型=“数字"的 HTML5 输入框Chrome 浏览器不接受逗号

2022-01-17 00:00:00 input numbers comma html

我正在使用带有 type="number" 的 HTML5 输入框.关于某些文档,如果我也使用 lang="" 属性,应该可以输入带逗号(不带句点)的数字.它适用于 Firefox,但不适用于 Chrome(不接受逗号).如何让 Chrome 接受输入框中的逗号.我的问题是我们的德国用户希望他们可以在此处输入逗号而不是句点.

I am using a HTML5 input box with type="number". Regarding to some documentations, it should be possible to enter a number with comma (not with period) if I also use the lang="" attribute. It is working in Firefox, but not in Chrome (does not accept a comma). How can I get Chrome to accept the comma in the input box. My problem is that our German users expect that they can enter a comma instead of a period there.

https://jsfiddle.net/byte2702/y3Lpfw7m/

Please enter a number with comma: <br/>
<input id="num" type="number" step="any" lang="de" pattern="-?[0-9]+[,.]*[0-9]+" /> 

推荐答案

截至目前(30/08/2017),Antoine Thiry 的回答在 Chrome 中似乎不再有效(我的版本是 60.0.3112.113).不幸的是,除了用 javascript 模拟 type="number" 之外,我没有任何其他建议.

As of now (30/08/2017), Antoine Thiry's answer seems to be no longer valid in Chrome (my version is 60.0.3112.113). Unfortunately I don't have any other suggestion, other than simulating type="number" with javascript.

相关文章