accesskey

accesskey 全局属性 提供了为当前元素生成键盘快捷键的提示。属性值必须由单个可打印字符组成(其中包括重音字符和可由键盘生成的其他字符)。

¥The accesskey global attribute provides a hint for generating a keyboard shortcut for the current element. The attribute value must consist of a single printable character (which includes accented and other characters that can be generated by the keyboard).

Try it

注意:在 WHATWG 规范中,它表示你可以指定多个空格分隔的字符,浏览器将使用它支持的第一个字符。但是,这在大多数浏览器中不起作用。IE/Edge 使用它支持的第一个命令没有问题,只要不与其他命令冲突。

¥Note: In the WHATWG spec, it says you can specify multiple space-separated characters, and the browser will use the first one it supports. However, this does not work in most browsers. IE/Edge uses the first one it supports without problems, provided there are no conflicts with other commands.

激活 accesskey 的方式取决于浏览器及其平台:

¥The way to activate the accesskey depends on the browser and its platform:

视窗 Linux 苹果
火狐浏览器 Alt + Shift + key
  • 火狐 57+: Control + Option + keyControl + Alt + key

    ¥Firefox 57+: Control + Option + key or Control + Alt + key

  • 火狐 14-56: Control + Alt + key

    ¥Firefox 14-56: Control + Alt + key

  • Firefox 13 或更早版本: Control + key

    ¥Firefox 13 or older: Control + key

边缘 Alt + key Control + Option + key
Control + Option + Shift + key
n/a
谷歌浏览器 Control + Option + key
苹果浏览器 n/a Control + Option + key
歌剧 15+ Alt + key Control + Alt + key
歌剧 12 Shift + Esc 打开可用快捷键列表。按 key 从列表中选择一个项目。

无障碍问题

¥Accessibility concerns

除了浏览器支持不佳之外,accesskey 属性还存在许多问题:

¥In addition to poor browser support, there are numerous concerns with the accesskey attribute:

  • accesskey 值可能与系统或浏览器键盘快捷键或辅助技术功能冲突。适用于操作系统、辅助技术和浏览器的一种组合的方法可能不适用于其他组合。
  • 某些 accesskey 值可能不会出现在某些键盘上,尤其是在考虑国际化时。因此,适应特定语言可能会导致进一步的问题。
  • 依赖于数字的 accesskey 值可能会让有认知问题的个人感到困惑,因为数字与其触发的功能没有逻辑关联。
  • 通知用户 accesskey 存在,以便他们了解该功能。如果系统缺乏通知用户此功能的方法,用户可能会意外激活 accesskey

由于这些问题,通常建议不要对大多数通用网站和 Web 应用使用 accesskey

¥Because of these issues, it is generally advised not to use accesskeys for most general-purpose websites and web apps.

规范

Specification
HTML Standard
# the-accesskey-attribute

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看