0

Hi we have an HTML5 website which will be accessed via iPad (similar to kiosk application). Website prompts user to type their PIN number. What I want is to force iPad to display numpad keyboard when user focuses on PIN textbox. It will be used by very old people and by default to switch to numpad in iPad keyborad you have to click "123" button. Older people wouldn't know that.

Can I use something like

<input type="number" />
4

2 回答 2

2

您可以在 中设置文本字段的类型,number它将显示标准的 1-9 拨号盘式键盘。

例子:

<input type="number" />

来源:http: //developer.apple.com/library/safari/#documentation/appleapplications/reference/SafariHTMLRef/Articles/InputTypes.html

于 2012-07-09T05:17:14.110 回答
1

您可以使用 HTML5 的新文本框类型(数字)。当浏览器不需要它时,它默认为常规文本框。要使用它将输入类型设置为数字。例如:

<input type="number" />

另一种解决方案是使用 Javascript。您可以使用 jQuery UI 的数字选择器、jStepper之类的插件,或者只需添加以下代码来限制普通文本框。

$(document).ready(function() {
    $(".text_field").keydown(function(event) {
        if ( event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 27 || event.keyCode == 13 || 
         // Allow: Ctrl+A
        (event.keyCode == 65 && event.ctrlKey === true) || 
         // Allow: home, end, left, right
        (event.keyCode >= 35 && event.keyCode <= 39)) {
             // let it happen, don't do anything
             return;
    }
    else {
        // Ensure that it is a number and stop the keypress
        if (event.shiftKey || (event.keyCode < 48 || event.keyCode > 57) && (event.keyCode < 96 || event.keyCode > 105 )) {
            event.preventDefault(); 
        }   
    }
});

});

资料来源:如何使用 jQuery 在 HTML 输入框中只允许数字(0-9)?

于 2012-07-09T05:28:51.783 回答