html input decimal,HTML Number Input removes decimal point?

Support to is still very limited, incomplete, and buggy.

For example, there is no support on IE 10 and Firefox 19. On them, the element falls back to an element, which means that any string is accepted as input and passed to the server as such, with no checking.

On browsers that support it, such as Chrome, the behavior varies, and is expected to vary, since the HTML5 CR definition intentionally leaves it open: the browser is required to provide a widget for numeric input somehow and guarantee that the data eventually sent to the server is correct as per the attributes of the element (within the given range, etc.).

In practice, the implementation depends on the locale of the browser, and you cannot control that as an author. This means that a browser might accept 88.2, or it might accept 88,2 (and internally convert it to 88.2), or it might accept both, or it might, in principle, accept input in hieroglyphs only (and internally convert it to the canonical form). It might even parse the user input so that any extra characters are just discarded, which means that 88FOO as well as 88.2 might be truncated to 88 when comma is the decimal separator.

What happens in your case is difficult to decide, since the browsers and platforms have not been described, and it is unclear what the server gets. But the important thing is that cannot be relied on, at all. It can be used in a controlled environment where everyone uses the same version of the same browser in the same operating system, up to and including language version and locale settings. Otherwise, use for numeric input and parse the input server-side and optionally pre-check it client-side, and make sure you inform the user of the expected format of input (such as decimal comma vs. decimal point).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值