Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/372.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
Javascript KeyboardEvent.location不返回任何内容_Javascript_Jquery_Keyboard Events_Jquery Events - Fatal编程技术网

Javascript KeyboardEvent.location不返回任何内容

Javascript KeyboardEvent.location不返回任何内容,javascript,jquery,keyboard-events,jquery-events,Javascript,Jquery,Keyboard Events,Jquery Events,我有一段代码: $('body').on('keydown', function(e) { console.log(e.location) }); 看起来e.location没有返回任何内容,控制台上显示“未定义”。 基本任务是检测何时按下左换档,何时按下右换档。 我去谷歌找到了,但它对我不起作用。 有什么建议吗?我相信你想要的是e.originalEvent.location-我在e对象周围进行了一些窥探,发现了以下内容: 右移: altKey: false bubbles: tru

我有一段代码:

$('body').on('keydown', function(e) {
    console.log(e.location)
});
看起来e.location没有返回任何内容,控制台上显示“未定义”。 基本任务是检测何时按下左换档,何时按下右换档。 我去谷歌找到了,但它对我不起作用。
有什么建议吗?

我相信你想要的是
e.originalEvent.location
-我在
e
对象周围进行了一些窥探,发现了以下内容:

右移:

altKey: false
bubbles: true
cancelable: true
char: undefined
charCode: 0
ctrlKey: false
currentTarget: body
data: undefined
delegateTarget: body
eventPhase: 2
handleObj: Object
isDefaultPrevented: returnFalse()
jQuery21406245628797914833: true
key: undefined
keyCode: 16
metaKey: false
originalEvent: KeyboardEvent
  altKey: false
  bubbles: true
  cancelBubble: false
  cancelable: true
  charCode: 0
  ctrlKey: false
  currentTarget: null
  defaultPrevented: false
  detail: 0
  eventPhase: 0
  isTrusted: true
  isTrusted: true
  keyCode: 16
  keyIdentifier: "Shift"
  keyLocation: 2
  location: 2         // <---------------------
altKey:false
泡泡:真的
可取消:正确
字符:未定义
字符编码:0
克特尔基:错
当前目标:身体
数据:未定义
授权对象:机构
活动阶段:2
handleObj:对象
isDefaultPrevented:returnFalse()
jQuery21406245628797914833:正确
关键字:未定义
密码:16
元键:false
originalEvent:KeyboardEvent
altKey:错误
泡泡:真的
取消泡泡:错误
可取消:正确
字符编码:0
克特尔基:错
currentTarget:null
默认值:false
详情:0
事件阶段:0
伊斯特鲁斯特:是的
伊斯特鲁斯特:是的
密码:16
键标识符:“移位”
关键位置:2
地点:2//
altKey: false
bubbles: true
cancelable: true
char: undefined
charCode: 0
ctrlKey: false
currentTarget: body
data: undefined
delegateTarget: body
eventPhase: 2
handleObj: Object
isDefaultPrevented: returnFalse()
jQuery21406245628797914833: true
key: undefined
keyCode: 16
metaKey: false
originalEvent: KeyboardEvent
  altKey: false
  bubbles: true
  cancelBubble: false
  cancelable: true
  charCode: 0
  ctrlKey: false
  currentTarget: null
  defaultPrevented: false
  detail: 0
  eventPhase: 0
  isTrusted: true
  isTrusted: true
  keyCode: 16
  keyIdentifier: "Shift"
  keyLocation: 2
  location: 1         // <---------------------