Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在jQuery keydown事件处理程序中检测SHIFT键?_Jquery_Events_Keyboard - Fatal编程技术网

如何在jQuery keydown事件处理程序中检测SHIFT键?

如何在jQuery keydown事件处理程序中检测SHIFT键?,jquery,events,keyboard,Jquery,Events,Keyboard,我有以下jQuery函数 jQuery.fn.integerMask = function () { return this.each(function () { $(this).keydown(function (e) { var key = (e.keyCode ? e.keyCode : e.which); // allow backspace, tab, delete, arrows, numbers and keypad numbers ONLY retur

我有以下jQuery函数

jQuery.fn.integerMask =
function () {
return this.each(function () {
  $(this).keydown(function (e) {
    var key = (e.keyCode ? e.keyCode : e.which);
    // allow backspace, tab, delete, arrows, numbers and keypad numbers ONLY
    return (
              key == 8 ||
              key == 9 ||
              key == 46 ||
              key == 37 ||
              key == 39 ||
              (key >= 48 && key <= 57) ||
              (key >= 96 && key <= 105));
              );
      });
    });
  };
jQuery.fn.integerMask=
函数(){
返回此。每个(函数(){
$(此).keydown(函数(e){
var key=(e.keyCode?e.keyCode:e.which);
//仅允许退格、制表符、删除、箭头、数字和键盘数字
返回(
键==8||
键==9||
键==46||
键==37||
键==39||
(键>=48&&key=96&&key

功能isKeyPressed(事件)
{
if(event.shiftKey==1)
{
警报(“按下了shift键!”);
}
其他的
{
警报(“未按下shift键!”);
}
}
单击文档中的某个位置。一个警报框将告诉您是否按了shift键

关键字->事件.shiftKey


来源:

这是一个布尔值
e.shiftKey
来详细说明David的评论。您需要做的是测试e.shiftKey=true是否表示按下了shift键,然后返回false。
<!DOCTYPE html>
<html>
<head>
<script>
function isKeyPressed(event)
{
if (event.shiftKey==1)
  {
  alert("The shift key was pressed!");
  }
else
  {
  alert("The shift key was NOT pressed!");
  }
}
</script>
</head>

<body onmousedown="isKeyPressed(event)">

<p>Click somewhere in the document. An alert box will tell you if you pressed the shift key or not.</p>

</body>
</html>