目前,我正在使用HTML、js和phonegap来编写Android应用程序。这是我用来捕获虚拟键盘上的 Enter 按钮的函数:
function handleFormKeypress(e)
{
var currentInputElement = $(e.target);
if(e.keyCode == 13 || e.keyCode == 10)
{
Log("handleFormKeypress - Go pressed")
//this needs to be checks as passing in the 'submitButton' is optional
if (e.data != undefined)
{
if (e.data.handler != undefined)
{
e.data.handler();
}
}
currentInputElement.blur();
e.stopImmediatePropagation();
return false;
}
}
正如你所看到的,我捕捉到了键盘的键码。使用 Phonegap 转换为 Android 应用程序,它应该捕获虚拟键盘的“Go”按钮或“Next”按钮。
我的输入字段的类型是数字:
<input type="number" id="blah blah blah"/>
在这种情况下,Android 虚拟键盘会显示带有下一个按钮的数字键盘。
我在几部 Android 手机上进行了测试。当我点击下一页按钮时,它按照我的预期跳到下一页。但在某些 HTC 手机上,例如 HTC Nexus One 和 HTC One X,它什么也不做。
有人有什么想法吗?
提前致谢。
最佳答案
同时使用e.keyCode
和e.which
怎么样?
添加内联 if 语句来检查两者:
function handleFormKeypress(e)
{
var currentInputElement = $(e.target);
var keyCode = (e.keyCode ? e.keyCode : e.which);
if(keyCode == 13 || keyCode == 10)
{
Log("handleFormKeypress - Go pressed")
//this needs to be checks as passing in the 'submitButton' is optional
if (e.data != undefined)
{
if (e.data.handler != undefined)
{
e.data.handler();
}
}
currentInputElement.blur();
e.stopImmediatePropagation();
return false;
}
关于javascript - HTC 手机虚拟键盘上无法捕捉回车按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18050330/