我已经定义了在桌面上运行良好的键盘事件,但对于没有获得屏幕键盘事件的触摸设备.如果用户正在输入,我需要捕获.我使用了以下代码段:
I have defined keyboard events which is working good in desktop but for touch devices not getting the onscreen keyboard event. I need to capture if user is typing. I have used the following segment of code :
$('#id').keydown(function(e){
//some code here
});
$('#id').keyup(function(e){
//some code here
})
我希望 keydown
和 keyup
中定义的代码即使对于触摸设备(平板电脑和手机)也能触发.请建议如何捕获屏幕键盘事件并使上述代码运行.
I want the code defined in keydown
and keyup
to trigger even for touch devices (both tablets and mobiles). Please suggest how to capture the onscreen keyboard event and make the above code to run.
你试过用按键代替按键吗
Have you tried using key press instead of key down
$("#id").keypress(function() {
});
更新:
由于 android 的问题,我现在通常像这样包装我的支票
Due to android problems I now normally wrap my checks like this
if ($.browser.mozilla) {
$("#id").keypress (keyPress);
} else {
$("#id").keydown (keyPress);
}
function keyPress(e){
doSomething;
}
这篇关于如何捕获触摸设备的屏幕键盘“keydown"和“keyup"事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!