gpt4 book ai didi

javascript - 有没有办法默认打开 'alphanumeric'键盘数字?

转载 作者:行者123 更新时间:2023-12-03 11:56:17 25 4
gpt4 key购买 nike

我正在使用 Phonegap 和 HTML5 开发一个 Web 应用程序。

当专注于文本输入时,系统要求我打开显示“数字”键的“字母数字”键盘。

这可能吗?

最佳答案

电话:<input type="tel" name="usrtel">

这将打开一个字母数字键盘。这可以是您想要的任何号码,而不仅仅是电话号码:-)

“tel”类型是新类型,来自 html5。有关所有输入类型的概述可以在这里找到:W3Schools

周一编辑2014 年 9 月 1 日下午 4:30:我正在编辑我的答案,因为乔纳斯·格鲁曼给出了答案。您应该使用<input type="tel"仅用于数字。就像所描述的类型:例如电话号码。如果用户输入十进制数字,则此输入类型将无法识别它。

如果您希望用户输入十进制数字,您必须使用此处给出的答案“模式”来执行此操作,您应该像这样使用它们:

HTML

<input type="text">

和 JS(请考虑:这些是您需要的命令 jQuery/jQuery-mobile

$('input[type="text"]').on('touchstart', function() {
$(this).attr('type', 'number');
});

$('input[type="text"]').on('keydown blur', function() {
$(this).attr('type', 'text');
});

为了完整起见,我将引用在此给出此答案的用户 -> Force iOS numeric keyboard with custom currency pattern

The idea is simple. The input starts off and ends up with type="text", but it briefly becomes type="number" on the touchstart event. This causes the correct iOS keyboard to appear. As soon as the user begins to enter any input or leave the field, the input becomes type="text" once again, thus circumventing the validation.

There's one downside to this method. When the user returns to an input that has already been filled out, the input will be lost (if it doesn't validate). This means the user won't be able to go back and edit previous fields. In my case, this isn't all that bad because the user may want to use the calculator over and over again with different values, so automatically deleting the input will save them a few steps. However, this may not be ideal in all cases.

It looks like Mobile Safari supports the new HTML5 input type attributes of email, number, search, tel, and url. These will switch the keyboard that is displayed. See the type attribute.

如果还有其他问题,请告诉我,我会再次编辑。

关于javascript - 有没有办法默认打开 'alphanumeric'键盘数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25606605/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com