我已经看过jQuery事件键:哪个键被按下了? 并且如何使用jquery检查点击事件期间按键是否被按下?
不过我的问题是,如果您能为所有浏览器获得相同的密钥事件? 目前,我知道Firefox给出了代码224的命令按钮(Mac),而Chrome和Safari则赋予其值91.最简单的方法是检查用户正在使用的浏览器,并按下按键或者按照方法所以我可以在所有浏览器上获得1个关键代码? 注意我得到的值:
var code = (evt.keyCode ? evt.keyCode : evt.which);如果可能,我很乐意不使用插件,因为我只需要知道关于命令 / ctrl (Windows系统)的按键。
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已经处理了。 要检查控制是否按下,您应该使用:
$(window).keydown(function (e){ if (e.ctrlKey) alert("control"); });修饰键列表:
e.ctrlKey e.altKey e.shiftKey正如fudgey所说:
e.metaKey可能在MAC上工作。 这里也有其他一些方法 。
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.shiftKeyAnd as fudgey suggested:
e.metaKeyMight work on MAC. Some other ways here as well.
更多推荐
发布评论