在HTML5数字输入中强制小数点而不是逗号(客户端) [英] Force decimal point instead of comma in HTML5 number input (client-side)
问题描述
我已经看到一些浏览器本地化了 input type =number
数字符号。
现在,在我的应用程序显示经度和纬度坐标的字段中,我得到了诸如51,983之类的东西,它应该是51.982559。我的解决方法是使用 input type =text
来代替,但我希望使用正确显示小数的数字输入。
在数字输入中是否有强制浏览器使用小数点的方法,无论客户端本地设置如何?
$ b $ (不言而喻,在我的应用程序中,无论如何,在服务器端更正这一点,但在我的设置中,我也需要它在客户端是正确的(因为一些JavaScript))。
预先致谢。
UPDATE b截至现在,在Windows 7上检查Chrome版本28.0.1500.71 m,输入的数字只是不接受用逗号格式化的小数。建议使用 step 属性的建议似乎无效。
通过将 step 属性指定为所需小数的精度,您的html5数字输入将接受小数。例如。取值为10.56;我的意思是2位小数位数,做到这一点:
< input type =numberstep =0.01min = 0>
您可以进一步指定 max 属性为最大允许值。
I have seen that some browsers localize the input type="number"
notation of numbers.
So now, in fields where my application displays longitude and latitude coordinates, I get stuff like "51,983" where it should be "51.982559". My workaround is to use input type="text"
instead, but I'd like to use the number input with correct display of decimals.
Is there a way to force browsers to use a decimal point in the number input, regardless of client-side local settings?
(It goes without saying that in my application I anyway correct this on the server side, but in my setup I also need it to be correct on the client side (because of some JavaScript)).
Thanks in advance.
UPDATE
As of right now, checking in Chrome Version 28.0.1500.71 m on Windows 7, the number input just does not accept decimals formatted with a comma. Proposed suggestions with the step
attribute do not seem to work.
With the step attribute specified to the precision of the decimals you want, your html5 numeric input will accept decimals. eg. to take values like 10.56; i mean 2 decimal place numbers, do this:
<input type="number" step="0.01" min="0" >
You can further specify the max attribute for the maximum allowable value.
这篇关于在HTML5数字输入中强制小数点而不是逗号(客户端)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!