我想用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”是控制键和一个键一起按下... –