启用数字键盘上的PhoneGap回车键 [英] Enable enter key on numeric keyboard in PhoneGap

查看:284
本文介绍了启用数字键盘上的PhoneGap回车键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们都在Android上运行的3.22 PhoneGap的2.6(也jQuery Mobile的骨干也都在混合)。我们希望把它使用户可以敲击回车键在字段中输入一个值后,提交表单。该字段为数字输入。

We are running PhoneGap 2.6 on Android 3.22 (also jquery mobile and backbone are also in the mix). We want to make it so the user can tap the enter key to submit a form after entering a value in a field. The field is a numeric input.

<input id="myfield" type="number">

不幸的是,在软键盘上的回车键似乎被禁用。所以,当你点击它,没有触发事件。以下工作无:

Unfortunately, the enter button on the soft keyboard appears to be disabled. So when you tap it, no event is fired. None of the following work:

$('#myfield').on('keyup', keyhandler);
$('#myfield').on('keydown', keyhandler);
$('#myfield').on('keypress', keyhandler);
$('#myfield').keyup(keyhandler);
$('#myfield').keydown(keyhandler);
$('#myfield').keypress(keyhandler);

keyhandler: function(e) {
    console.log('You tapped a key');
    if (e.keyCode  == 13) {
        console.log('You tapped ENTER! Yay!');
    }
}

有没有一种方法,使数字键盘上的回车键?

Is there a way to enable the enter button on a numeric keyboard?

推荐答案

不知道这是否与您的问题...但你可以模拟表单提交类似于发生在你通过$ P $上的开始点击通过数字键盘上的下一步按钮PSS。您可以通过JQuery的使用下面的绑定检测下键盘preSS:

Not sure if this relates to your problem... but you can simulate form submit similar to what happens when you click on 'Go' via a press via the 'Next' button on a numeric keyboard. You can detect the next keyboard press by using the following bind in JQuery:

$('input').on('keydown', function(e){
    if(e.which === 9) {
        //your code here
    }
});

下一步按钮,模拟键盘,这是关键code 9.遗憾的是,关键preSS和KeyUp事件不检测的下一个关键事件上的Tab键preSS事件,所以你需要绑定它的keydown。

The 'next' button emulates the tab keypress event on a keyboard, which is key code 9. Unfortunately, keypress and keyup events do not detect the next key event, so you need to bind it on keydown.

这篇关于启用数字键盘上的PhoneGap回车键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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