用于命令键的jQuery键代码 [英] jQuery key code for command key
问题描述
我已阅读 jQuery事件按键:按了哪个按键?和如何检查如果在使用jquery的点击事件期间按下了键?
但是我的问题是如果你能为所有浏览器获得相同的键事件?目前我知道Firefox给了命令按钮(Mac)代码224,而Chrome和Safari给它的值为91.是最好的方法,只需检查用户正在使用的浏览器,或者有一种方法,以便我可以获得1键代码跨所有浏览器?
注意我得到的值:
var code =(evt.keyCode?evt.keyCode:evt 。哪一个);
我不想使用插件,如果可能只是因为我只需要知道
jQuery已经处理过的命令 / ctrl 那。要检查是否按下控件,应该使用:
$(window).keydown(function(e){
if(e.ctrlKey)alert(control);
});
修饰键列表:
e.ctrlKey
e.altKey
e.shiftKey
和fudgey建议的:
e.metaKey
pre>
I have read jQuery Event Keypress: Which key was pressed? and How can i check if key is pressed during click event with jquery?
However my question is if you can get the same key event for all browsers? Currently I know that Firefox gives the command button (Mac) the code 224 while Chrome and Safari give it the value 91. Is the best approach to simply check what browser the user is using and base the key pressed on that or is there a way so that I can get 1 key code across all browsers? Note I am getting the value with the:
var code = (evt.keyCode ? evt.keyCode : evt.which);
I would love to not use a plugin if possible just because I only need to know about the command/ctrl (windows system) key pressed.
解决方案jQuery already handles that. To check if control was pressed you should use:
$(window).keydown(function (e){ if (e.ctrlKey) alert("control"); });
The list of modifier keys:
e.ctrlKey e.altKey e.shiftKey
And as fudgey suggested:
e.metaKey
Might work on MAC. Some other ways here as well.
这篇关于用于命令键的jQuery键代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!