“输入/下一个”的行为进入数字字段时,在移动浏览器上输入密码 [英] Behavior of "enter/next" key on mobile browsers when entering into a number field

查看:93
本文介绍了“输入/下一个”的行为进入数字字段时,在移动浏览器上输入密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



 < input type =number min =0max =9999999id =inSkuname =inSku> 

之前,我使用 type =text,但在默认情况下提供完整键盘的移动浏览器上,所涉及的方框仅需要输入数字。从逻辑上讲,当移动浏览器专注于 type =number字段时,它将变为唯一号码键盘 - 但是,我目前正在依靠一点 jQuery 来处理表单内容的提交。代码如下:

  $(#inSku)。keyup(function(event){
if(event .keyCode == 13){
ringItem();
}
});

这里的问题是,在股票的Android手机键盘(和我假设很多其他移动浏览器) - 使用数字键盘时,常规字母数字安卓键盘上的输入键已更改为下一个按钮。在我的情况下,这个按钮需要输入文本并将其粘贴在地址栏中,这并不完全理想。有没有什么办法来利用键盘上的下一个按钮,并得到它来执行我的其他javascript函数?

尝试 p>

  $('#inSku')。keyup(function(e){
alert('Key pressed':'+ e .keyCode);
});

这里的想法是按下 next 按钮并找到该密钥代码。一旦你这样做了,你可以将它添加到你的逻辑中,比如if(event.keyCode === 13 || event.keyCode === ...)。您可以根据需要添加尽可能多的限定符来支持多键盘和设备。


I've got a single line of code (no forms involved) here:

<input type="number" min="0" max="9999999" id="inSku" name="inSku">

Before, I was using type="text", but on mobile browsers that gave the full keyboard by default and the box in question only takes number inputs. Logically, the mobile browsers will change to an only-number keyboard when they focus on a type="number" field - however, I am currently relying on a little bit of jQuery to handle the submission of the content of the form. Here's that code:

$("#inSku").keyup(function (event) {
    if (event.keyCode == 13) {
        ringItem();
    }
});

The problem here being that on the stock android phone keyboard (and I'm assuming a good number of other mobile browsers) - when using the "number" keyboard, the enter key that is on the regular alphanumeric android keyboard has changed to a "next" button. This button in my case takes the text input and sticks it in the address field, not exactly ideal. Is there any way to harness the next button on the keyboard and get that to execute my other javascript function?

解决方案

Try

 $('#inSku').keyup(function (e) {
   alert('Key pressed: ' + e.keyCode);
 });

The idea here is to press the next button and find that key code. Once you do, you can add it to your logic like if (event.keyCode === 13 || event.keyCode === ...). You can add as many qualifiers as you need to to support multiple keypads and devices.

这篇关于“输入/下一个”的行为进入数字字段时,在移动浏览器上输入密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆