用于命令键的jQuery键代码(jQuery key code for command key)

编程入门 行业动态 更新时间:2024-10-26 22:28:11
用于命令键的jQuery键代码(jQuery key code for command key)

我已经看过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.shiftKey

And as fudgey suggested:

e.metaKey

Might work on MAC. Some other ways here as well.

更多推荐

本文发布于:2023-07-16 13:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1129049.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:命令   代码   jQuery   command   key

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!