简体   繁体   English

jQuery Mobile:仅数字输入字段?

[英]jQuery Mobile: Numbers only input field?

I'm making a website based on jQuery Mobile. 我正在建立一个基于jQuery Mobile的网站。 On a particular field I would like to accept only numbers, or more precisely 4 digits. 在特定字段上,我只接受数字,或更准确地说是4位数字。 I noticed that the slider input does this (when you tap the field on your phone it brings up a "numbers only keyboard"). 我注意到滑块输入可以做到这一点(当您点击手机上的字段时,它会弹出一个“仅数字键盘”)。

However I'm not interested in the slider itself as this as I want the user to type in an exact number (for example 4687 is a bit hard to achive with a slider on a touch phone). 但是,我对滑条本身不感兴趣,因为我希望用户输入确切的数字(例如,在触摸电话上使用滑条很难达到4687)。

Is there an alternative to the slider or is there a neat way to hide the actual slider? 有没有替代滑块的方法,还是有一种巧妙的方法来隐藏实际的滑块?

<div data-role="fieldcontain">
    <fieldset data-role="controlgroup">
        <label for="slc_length">
            Length
        </label>
        <input type="range" name="slider" id="slc_length" value="500" min="8" max="9999" data-highlight="true" />
    </fieldset>
</div>

Use input type of number. 使用数字的输入类型。 Don't give up on server side validation though! 但是不要放弃服务器端验证!

<input type="number" name"abc">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM