admin管理员组文章数量:1431726
In the below switch statement when left key is pressed, it alerts left and when top key is pressed it alerts top. How can i make a case for bination of both shift and left key.
$(document).keydown(function(e) {
switch (e.which) {
case 37: alert('left'); //left arrow key
break;
case 38: alert('top');; //up arrow key
break;
case ??: alert('shift + left'); //How can i make this repond to the bination of shift + left arrow keys.
break;
}
});
In the below switch statement when left key is pressed, it alerts left and when top key is pressed it alerts top. How can i make a case for bination of both shift and left key.
$(document).keydown(function(e) {
switch (e.which) {
case 37: alert('left'); //left arrow key
break;
case 38: alert('top');; //up arrow key
break;
case ??: alert('shift + left'); //How can i make this repond to the bination of shift + left arrow keys.
break;
}
});
Share
Improve this question
asked May 12, 2011 at 21:27
PinkiePinkie
10.3k22 gold badges81 silver badges124 bronze badges
1 Answer
Reset to default 7The shift key is a modifier, and can be checked in the case statement for the left key.
$(document).keydown(function(e) {
switch (e.which) {
case 37:
if (e.shiftKey) {
alert('shift+left'); // shift and left arrow key
}
else {
alert('left'); //left arrow key
}
break;
case 38:
alert('top'); //up arrow key
break;
}
});
Demo: http://jsfiddle/ZL9Fx/1/
本文标签: javascriptjQuery ewhich in switch statementStack Overflow
版权声明:本文标题:javascript - jQuery e.which in switch statement - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745571743a2664089.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论