TouchEvent:altKey 属性

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

TouchEvent 接口的只读 altKey 属性但会一个布尔值,指示在创建触摸事件时是否启用 alt(Alternate)键。如果启用了 alt 键,则属性为 true。否则为 false

此属性为 只读

一个布尔值,如果为此事件启用了 alt 键则为 true;如果未启用 alt 键则为 false

示例

这个例子展示了如何访问 TouchEvent 的修饰键属性:TouchEvent.altKeyTouchEvent.ctrlKeyTouchEvent.metaKeyTouchEvent.shiftKey

在以下代码片段中,touchstart 事件处理器记录了事件的修饰键状态。

js
someElement.addEventListener(
  "touchstart",
  (e) => {
    // 记录事件的修饰键状态
    console.log(`altKey = ${e.altKey}`);
    console.log(`ctrlKey = ${e.ctrlKey}`);
    console.log(`metaKey = ${e.metaKey}`);
    console.log(`shiftKey = ${e.shiftKey}`);
  },
  false,
);

规范

Specification
Touch Events
# dom-touchevent-altkey

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
altKey

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Has more compatibility info.