accesskey

HTML accesskey Attribute (HTML访问密钥属性)

The HTML accesskey attribute is a global attribute and specifies a shortcut key for activating/focusing a specific element. The attribute value should consist of one printable character. (HTML accesskey属性是一个全局属性,指定用于激活/聚焦特定元素的快捷键。属性值应由一个可打印字符组成。)

In HTML4.1, the accesskey attribute can be only used with the following elements: <a>, <area>, <button>, <input>, <label>, <legend>, and <textarea>.

In HTML5, this attribute can be used with any element. (在HTML5中,此属性可用于任何元素。)

The way of accessing the shortcut key varies from browser to browser. (访问快捷键的方式因浏览器而异。)

When there is more than one element having the same accesskey, the behavior of the browser differs: (当多个元素具有相同的访问密钥时,浏览器的行为会有所不同:)

  • Google Chrome and Safari: The last element having the accesskey will be activated. (- Google Chrome和Safari :最后一个具有访问密钥的元素将被激活。)

  • Opera: The first element having the accesskey will be activated. (- Opera :第一个具有访问键的元素将被激活。)

  • Mozilla Firefox: The next element having the accesskey will be activated. (- Mozilla Firefox :下一个具有访问密钥的元素将被激活。)

Besides poor browser support, there are other concerns with the accesskey attribute: (除了浏览器支持不佳外, accesskey属性还存在其他问题:)

  • An accesskey value may cause some problems connected with assistive technology functionality, or a system and browser keyboard shortcut. (-访问键值可能会导致与辅助技术功能或系统和浏览器键盘快捷键相关的一些问题。)

  • Some accesskey value may be missing on some keyboards, in particular when there is a matter of internationalization. (-某些键盘上可能缺少一些访问键值,特别是在国际化问题上。)

  • An accesskey value consisting of numbers may be unclear to those with cognitive concerns. (-对于有认知问题的人来说,由数字组成的访问密钥值可能不清楚。)

For these reasons, it’s recommended not to use accesskey for multi-purpose websites and web apps. (>出于这些原因,建议不要对多用途网站和网络应用程序使用accesskey。)

Syntax

Syntax (语法)

<tag accessKey="single_character"></tag>

Example of the HTML accesskey attribute:

<!DOCTYPE html>
<html>
 <head>
   <title>Title of the document</title>
 </head>
 <body>
   <a href="https://www.w3cdoc.com/learn-html.html" accesskey="h">HTMLonline tutorial</a>
   <br/>
   <a href="https://www.w3cdoc.com/learn-css.html" accesskey="c">CSS online tutorial</a>
   <br/>
   <a href="https://www.w3cdoc.com/learn-git.html" accesskey="g">GIT online tutorial</a>
   <br/>
   <p>Chrome, Safari, Opera 15+: [ALT] + <strong>accesskey</strong></p>
   <p>Firefox: [ALT] [SHIFT] + <strong>accesskey</strong></p>
   <p>Opera prior version 15: [SHIFT] [ESC] + <strong>accesskey</strong></p>
 </body>
</html>


请遵守《互联网环境法规》文明发言,欢迎讨论问题
扫码反馈

扫一扫,反馈当前页面

咨询反馈
扫码关注
返回顶部