--- title: accessKeyLabel slug: Web/API/HTMLElement/accessKeyLabel translation_of: Web/API/HTMLElement/accessKeyLabel ---
HTMLElement.accessKeyLabel
只读属性返回一个 {{jsxref("String")}} 表示这个元素分配的访问密钥(如果有的话); 否则返回一个空字符串.
label = element.accessKeyLabel
var node = document.getElementById('btn1'); if (node.accessKeyLabel) { node.title += ' [' + node.accessKeyLabel + ']'; } else { node.title += ' [' + node.accessKey + ']'; } node.onclick = function () { var p = document.createElement('p'); p.textContent = 'Clicked!'; node.parentNode.appendChild(p); };
<button accesskey="h" title="Caption" id="btn1">Hover me</button>
{{ EmbedLiveSample('Example') }}
Specification | Status | Comment |
---|---|---|
{{SpecName('HTML WHATWG', "interaction.html#dom-accesskeylabel", "HTMLElement.accessKeyLabel")}} | {{Spec2('HTML WHATWG')}} | No change from initial definition. |
{{SpecName('HTML5.1')}} | {{Spec2('HTML5.1')}} | Removed. pull w3c/html#144, issue w3c/html#99, WICG discussion. |
{{SpecName('HTML5 W3C', "editing.html#dom-accesskeylabel", "HTMLElement.accessKeyLabel")}} | {{Spec2('HTML5 W3C')}} | Snapshot of {{SpecName('HTML WHATWG')}}, initial definition. |
{{Compat("api.HTMLElement.accessKeyLabel")}}