admin管理员组文章数量:1026925
$("#text").bind('keypress', function(e) {
var code = (e.KeyCode ? e.keyCode : e.which);
alert(code);
}
It works fine for everything except Alt, Ctrl, or Shift.
But in all tutorials that i found it should echos 17, 18, 19
Why?
$("#text").bind('keypress', function(e) {
var code = (e.KeyCode ? e.keyCode : e.which);
alert(code);
}
It works fine for everything except Alt, Ctrl, or Shift.
But in all tutorials that i found it should echos 17, 18, 19
Why?
Share Improve this question edited Nov 17, 2012 at 9:46 Be Brave Be Like Ukraine 7,7353 gold badges45 silver badges68 bronze badges asked Aug 27, 2010 at 2:42 QiaoQiao 17k32 gold badges96 silver badges120 bronze badges3 Answers
Reset to default 4use .keydown()
or .keyup()
see it in action
jQuery(function($){
var output = $('.output');
$("#text1").bind('keypress', function(e) {
var code = (e.KeyCode ? e.keyCode : e.which);
output.text(code);
});
$("#text2").bind('keydown', function(e) {
var code = (e.KeyCode ? e.keyCode : e.which);
output.text(code);
});
$("#text3").bind('keyup', function(e) {
var code = (e.KeyCode ? e.keyCode : e.which);
output.text(code);
});
})
<script src="https://ajax.googleapis./ajax/libs/jquery/1.4.2/jquery.min.js"></script>
keypress <input type="text" id="text1"> <br>
keydown <input type="text" id="text2"> <br>
keyup <input type="text" id="text3">
<br><br>
Output: <span class="output"></span>
Have you considered using the jquery.hotkeys extension that allows you to bind by specifying a string?
"C-A-q" would bind you to:
Control + Alt + q.
It would probably be better to use console.log to find them. You can also use just one textbox easily for this.
$("#textbox").keydown(function(e) {
console.log("keydown: "+e.keyCode);
});
And do the same for keyup and keypress to see better how it all works.
Side note: JavaScript sure is hard to write on a phone ;)
$("#text").bind('keypress', function(e) {
var code = (e.KeyCode ? e.keyCode : e.which);
alert(code);
}
It works fine for everything except Alt, Ctrl, or Shift.
But in all tutorials that i found it should echos 17, 18, 19
Why?
$("#text").bind('keypress', function(e) {
var code = (e.KeyCode ? e.keyCode : e.which);
alert(code);
}
It works fine for everything except Alt, Ctrl, or Shift.
But in all tutorials that i found it should echos 17, 18, 19
Why?
Share Improve this question edited Nov 17, 2012 at 9:46 Be Brave Be Like Ukraine 7,7353 gold badges45 silver badges68 bronze badges asked Aug 27, 2010 at 2:42 QiaoQiao 17k32 gold badges96 silver badges120 bronze badges3 Answers
Reset to default 4use .keydown()
or .keyup()
see it in action
jQuery(function($){
var output = $('.output');
$("#text1").bind('keypress', function(e) {
var code = (e.KeyCode ? e.keyCode : e.which);
output.text(code);
});
$("#text2").bind('keydown', function(e) {
var code = (e.KeyCode ? e.keyCode : e.which);
output.text(code);
});
$("#text3").bind('keyup', function(e) {
var code = (e.KeyCode ? e.keyCode : e.which);
output.text(code);
});
})
<script src="https://ajax.googleapis./ajax/libs/jquery/1.4.2/jquery.min.js"></script>
keypress <input type="text" id="text1"> <br>
keydown <input type="text" id="text2"> <br>
keyup <input type="text" id="text3">
<br><br>
Output: <span class="output"></span>
Have you considered using the jquery.hotkeys extension that allows you to bind by specifying a string?
"C-A-q" would bind you to:
Control + Alt + q.
It would probably be better to use console.log to find them. You can also use just one textbox easily for this.
$("#textbox").keydown(function(e) {
console.log("keydown: "+e.keyCode);
});
And do the same for keyup and keypress to see better how it all works.
Side note: JavaScript sure is hard to write on a phone ;)
本文标签: jqueryJavascript keycodes for AltCtrland ShiftStack Overflow
版权声明:本文标题:jquery - Javascript keycodes for Alt, Ctrl, and Shift - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1744385781a2094555.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论