在 HTML5 数字输入中强制使用小数点而不是逗号(客户端) [英] Force decimal point instead of comma in HTML5 number input (client-side)

查看:18
本文介绍了在 HTML5 数字输入中强制使用小数点而不是逗号(客户端)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到一些浏览器将数字的 input type="number" 符号本地化.

I have seen that some browsers localize the input type="number" notation of numbers.

所以现在,在我的应用程序显示经度和纬度坐标的字段中,我得到了51,983"之类的内容,而它应该是51.982559".我的解决方法是改用 input type="text",但我想使用正确显示小数的数字输入.

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?

(不用说,在我的应用程序中,无论如何我都会在服务器端纠正这个问题,但在我的设置中,我还需要它在客户端正确(因为一些 JavaScript).

(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)).

提前致谢.

更新截至目前,在 Windows 7 上检查 Chrome 版本 28.0.1500.71 m,输入的数字不接受逗号格式的小数.带有 step 属性的建议似乎不起作用.

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 stepattribute do not seem to work.

http://jsfiddle.net/AsJsj/

推荐答案

使用 step 属性指定您想要的小数精度,以及 lang 属性 [设置为使用 句点 格式化小数的区域设置],您的 html5 数字输入将接受小数.例如.取 10.56 之类的值;我的意思是 2 位小数,这样做:

With the step attribute specified to the precision of the decimals you want, and the lang attribute [which is set to a locale that formats decimals with period], 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" lang="en" value="1.99">

您可以进一步指定 max 属性以获得最大允许值.

You can further specify the max attribute for the maximum allowable value.

编辑向输入元素添加 lang 属性,其语言环境值使用点而不是逗号来格式化小数

Edit Add a lang attribute to the input element with a locale value that formats decimals with point instead of comma

这篇关于在 HTML5 数字输入中强制使用小数点而不是逗号(客户端)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆