HTMLLinkElement:href 属性
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
HTMLLinkElement
接口的 href
属性包含一个字符串,该字符串是与链接相关联的 URL。
它反映 <link>
元素的 href
属性。如果元素没有 href
属性,则此属性的值为空字符串(""
)。
备注:
每个 <link>
元素都必须包含 href
属性或 imagesrcset
属性中的一个或两个。这意味着,对于每个有效的 <link>
,此属性或 imageSrcset
都不会为空。
值
包含 URL 的字符串,如果没有 href
元素,则为空字符串(""
)。
示例
html
<link rel="stylesheet" href="example.css" />
js
const link = document.getElementsByTag("link")[0];
console.log(link.href); // 'example.css'
规范
Specification |
---|
HTML # dom-link-href |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
href |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.