html5 输入小数,如何使用HTML5输入类型编号处理浮点数和小数点分隔符

Im building web app which is mainly for mobile browsers. Im using input fields with number type, so (most) mobile browsers invokes only number keyboard for better user experience. This web app is mainly used in regions where decimal separator is comma, not dot, so I need to handle both decimal separators.

How to cover this whole mess with dot and comma?

My findings:

Desktop Chrome

Input type=number

User enters "4,55" to input field

$("#my_input").val(); returns "455"

I can not get the correct value from input

Desktop Firefox

Input type=number

User enters "4,55" to input field

$("#my_input").val(); returns "4,55"

Thats fine, I can replace comma with dot and get correct float

Android browser

Input type=number

User enters "4,55" to input field

When input loses focus, value is truncated to "4"

Confusing to user

Windows Phone 8

Input type=number

User enters "4,55" to input field

$("#my_input").val(); returns "4,55"

Thats fine, I can replace comma with dot and get correct float

What are the "best practices" in this kind of situations when user might use comma or dot as decimal separator and I want to keep html input type as number, to provide better user experience?

Can I convert comma to dot "on the fly", binding key events, is it working with number inputs?

EDIT

Currenlty I do not have any solution, how to get float value (as string or number) from input which type is set to number. If enduser enters "4,55", Chrome returns always "455", Firefox returns "4,55" which is fine.

Also it is quite annoying that in Android (tested 4.2 emulator), when I enter "4,55" to input field and change focus to somewhere else, the entered number get truncated to "4".

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值