【发布时间】:2015-06-02 21:44:58
【问题描述】:
我正在尝试使用 jQuery 找出用 ctrl 键按下的字符,但我无法找出代码。
例如:如果我按 ctrl+a 那么它应该提醒我 ctrl+a 被按下.
我正在使用下面的代码
$(document).keypress(function(e) {
if(e.ctrlKey){
var ch = String.fromCharCode(e.keyCode);
alert("key pressed ctrl+"+ch); //gives blank value in ch here, I need to know the character pressed
alert("key pressed ctrl+"+e.keyCode); //this works but gives me ASCII value of the key
}
});
【问题讨论】:
-
我检查了上面建议的 url 但这与我上面的问题不同,我需要知道按下的键的字符代码,而建议的 url 只捕获一个键。
标签: javascript jquery