我想用jquery hotkeys來捕捉按鍵事件。我無法捕捉空格鍵。有沒有人知道一個地方列出了熱鍵的所有按鍵代碼?jquery熱鍵的空格鍵
我的代碼:
$(document).bind('keypress', 'spacebar', function(){
alert('spacebar pressed');
})
我想用jquery hotkeys來捕捉按鍵事件。我無法捕捉空格鍵。有沒有人知道一個地方列出了熱鍵的所有按鍵代碼?jquery熱鍵的空格鍵
我的代碼:
$(document).bind('keypress', 'spacebar', function(){
alert('spacebar pressed');
})
你可以參考鍵碼here,
$(document).bind('keypress', function(e){
var key = e.keyCode ? e.keyCode : e.charCode; //get the key code
if (key == 32 && e.ctrlKey){//key code of space bar
alert('spacebar pressed with ctrl key..');
}
});
線26 - 113 jquery.hotkeys.js有許多它們是可讀的鑰匙。
32: "space"
你想用 「空間」,而不是 「空格鍵」。
該插件使用'普通'鍵爲String.fromCharCode(event.which)
。
specialKeys: {
8: "backspace",
9: "tab",
10: "return",
13: "return",
16: "shift",
17: "ctrl",
18: "alt",
19: "pause",
20: "capslock",
27: "esc",
32: "space",
33: "pageup",
34: "pagedown",
35: "end",
36: "home",
37: "left",
38: "up",
39: "right",
40: "down",
45: "insert",
46: "del",
59: ";",
61: "=",
96: "0",
97: "1",
98: "2",
99: "3",
100: "4",
101: "5",
102: "6",
103: "7",
104: "8",
105: "9",
106: "*",
107: "+",
109: "-",
110: ".",
111: "/",
112: "f1",
113: "f2",
114: "f3",
115: "f4",
116: "f5",
117: "f6",
118: "f7",
119: "f8",
120: "f9",
121: "f10",
122: "f11",
123: "f12",
144: "numlock",
145: "scroll",
173: "-",
186: ";",
187: "=",
188: ",",
189: "-",
190: ".",
191: "/",
192: "`",
219: "[",
220: "\\",
221: "]",
222: "'"
}
謝謝你的link.Yes它看起來像它的空間通過閱讀,但它不適合我當我鍵入「空間」...如果我給「A」或其他一些字母,然後正確地捕捉該按鍵...這是非常令人沮喪的:( –
你可以使用這個jQuery插件https://gist.github.com/d194103a0c9b11248a32.git
例如
$('div').hotkey('space bar', function() {
alert("Spacebar pressed....");
});
對我來說也是 「空間」 不起作用。我用代碼代替:
$('div').hotkey(32, function() {
alert("Spacebar pressed....");
});
這些是常規js的關鍵代碼。我正在檢查jquery熱鍵 - 例如。 「ctrl + a」是控制鍵和一個鍵一起按下... –