当前位置: 动力学知识库 > 问答 > 编程问答 >

html - Enforce numbers in mobile web form

问题描述:

I have a simple webform targeted for Opera Mini and Opera Mobile. I'm using just a HTML input element.

Now I would like to restrict the element to only have integer numbers. Is there a way to enforce this in this browser (possible even that the phone will have it's number mode on when entering the form)?

And if I wanted to allow floats, is something possible then?

网友答案:

You should be able to use the "number" input type, it's part of the HTML5 spec. I'm unsure if Opera will automatically display the numeric keypad but the iphone at least does...

网友答案:

In XHTML Basic, you can use inputmode="digits" on your <input> tags to accomplish this. It ought to be more widely supported on mobile browsers that HTML5 mechanisms.

网友答案:
<input type='tel' /> 

will bring up a numeric keypad on Android, WP8, and iPhone default browsers as well as Chrome for Android. On my Android browsers, non-numeric characters are stripped onblur.

<input type='number' /> 

should work fine for floats. On both of my Android browsers, it also automatically removes leading zeros onblur.

分享给朋友:
您可能感兴趣的文章:
随机阅读: