問題描述
我已經定義了在桌面上運行良好的鍵盤事件,但對于沒有獲得屏幕鍵盤事件的觸摸設備.如果用戶正在輸入,我需要捕獲.我使用了以下代碼段:
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"事件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!