ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
[TOC] > [参考](https://wangdoc.com/javascript/elements/a.html) ## 属性 ### URL 相关属性 ``` // <a id="test" href="http://user:passwd@example.com:8081/index.html?bar=1#foo">test</a> var a = document.getElementById('test'); a.hash // "#foo" a.host // "example.com:8081" a.hostname // "example.com" a.href // "http://user:passed@example.com:8081/index.html?bar=1#foo" a.origin // "http://example.com:8081" a.password // "passwd" a.pathname // "/index.html" a.port // "8081" a.protocol // "http:" a.search // "?bar=1" a.username // "user" ``` ### accessKey 读写<a>元素的快捷键 按 `Alt` + `k` ``` var a = document.getElementById('test'); a.accessKey = 'k'; ``` ### download 表示用户下载得到的文件名 ``` a.download = 'bar.jpg'; ``` ### rel 表示链接与当前文档的关系 ``` a.rel // "license" ``` ### tabIndex 在文档里面的 Tab 键遍历顺序 ``` a.tabIndex // 0 ``` ### target `a.target // "_blank" ` ### text 链接文本,等同于当前节点的textContent属性 `a.text // "test" ` ### type 链接目标的 MIME 类型 `a.type // "video/mp4" ` ## 方法 ### `blur()`:从当前元素移除键盘焦点 ### `focus()`:当前元素得到键盘焦点