KeyboardEvent.location read-only property returns an unsigned long representing the location of the key on the keyboard or other input device.

Possible values are:

常量 描述
DOM_KEY_LOCATION_STANDARD 0 The key has only one version, or can't be distinguished between the left and right versions of the key, and was not pressed on the numeric keypad or a key that is considered to be part of the keypad.
DOM_KEY_LOCATION_LEFT 1 The key was the left-hand version of the key; for example, the left-hand Control key was pressed on a standard 101 key US keyboard. This value is only used for keys that have more than one possible location on the keyboard.
DOM_KEY_LOCATION_RIGHT 2 The key was the right-hand version of the key; for example, the right-hand Control key is pressed on a standard 101 key US keyboard. This value is only used for keys that have more than one possible location on the keyboard.
DOM_KEY_LOCATION_NUMPAD 3

The key was on the numeric keypad, or has a virtual key code that corresponds to the numeric keypad.

注意: NumLock is locked, Gecko always returns DOM_KEY_LOCATION_NUMPAD for the keys on the numeric pad. Otherwise, when NumLock is unlocked and the keyboard actually has a numeric keypad, Gecko always returns DOM_KEY_LOCATION_NUMPAD too. On the other hand, if the keyboard doesn't have a keypad, such as on a notebook computer, some keys become Numpad only when NumLock is locked. When such keys fires key events, the location attribute value depends on the key. That is, it must not be DOM_KEY_LOCATION_NUMPAD . 注意: NumLock key's key events indicate DOM_KEY_LOCATION_STANDARD both on Gecko and Internet Explorer.
DOM_KEY_LOCATION_MOBILE Obsolete since Gecko 38 4

The key was on a mobile device; this can be on either a physical keypad or a virtual keyboard.

注意: Gecko always returns DOM_KEY_LOCATION_MOBILE on Android (Prior to 18), Maemo, and Boot to Gecko . However, at Gecko 38 , this is dropped.
DOM_KEY_LOCATION_JOYSTICK Obsolete since Gecko 38 5

The key was a button on a game controller or a joystick on a mobile device.

注意: Gecko never fires trusted key events with DOM_KEY_LOCATION_JOYSTICK except on Android. Starting 18, native key events on Android may have this value. However, at Gecko 38 , this is dropped.

句法

var location = event.location;
					

范例

function keyEvent(event) {
  console.log("Location of key pressed: " + event.location);
}
					

规范

规范 状态 注释
DOM (文档对象模型) 3 级事件规范
The definition of 'KeyboardEvent.location' in that specification.
过时 初始定义。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
location Chrome Yes Edge 12 Firefox 15 IE 9 Opera Yes Safari 6.1 WebView Android Yes Chrome Android Yes Firefox Android 15 Opera Android Yes Safari iOS 8 Samsung Internet Android Yes

图例

完整支持

完整支持

另请参阅

元数据

  • 最后修改: