HTML DOM accessKey 属性
JavaScript基础 2022-06-08 15:28:0815小码哥的IT人生shichen
HTML DOM accessKey 属性
定义和用法
accessKey 属性可设置或返回访问一个链接的键盘按键。
注释:请使用 Alt + accessKey 为拥有指定快捷键的元素赋予焦点。
语法
anchorObject.accessKey=accessKey
实例
下面的例子将为链接设置快捷键:
<html> <head> <script type="text/javascript"> function accesskey() { document.getElementById('php').accessKey="w"
} </script> </head> <body onload="accesskey()"> <a id="php" href="http://www.phpcodeweb.com/">phpcodeweb.com</a> </body> </html>
TIY
完整实例【向超链接添加快捷键】:
<html> <head> <script type="text/javascript"> function accesskey() { document.getElementById('php').accessKey="w" document.getElementById('phpcodeweb').accessKey="p" } </script> </head> <body onload="accesskey()"> <p><a id="php" href="http://www.phpcodeweb.com/">phpcodeweb.com</a> (请使用 Alt + w 给该链接赋予焦点)</p> <p><a id="phpcodeweb" href="http://www.phpcodeweb.com/news/93.html">HTML DOM</a> (请使用 Alt + p 为该链接赋予焦点)</p> </body> </html>
可以使用本站在线JavaScript测试工具测试上述代码运行效果:http://www.phpcodeweb.com/runjs.html