StyleSheet: href 屬性
StyleSheet 介面的 href 屬性返回樣式表的 URL。
此屬性是隻讀的。
值
一個包含樣式表 URI 的字串。
示例
假設 <head> 包含以下內容
html
<link rel="styleSheet" href="example.css" />
然後,如果您透過 Windows 上的 file:// URL 開啟 HTML 頁面,並執行以下指令碼
js
console.log(document.styleSheets[0].href);
結果看起來像這樣:“file:////C:/Windows/Desktop/example.css”。
注意
如果樣式表是連結樣式表,則其屬性值是其位置。對於內聯樣式表,此屬性的值為 null。
規範
| 規範 |
|---|
| CSS 物件模型 (CSSOM) # dom-stylesheet-href |
瀏覽器相容性
載入中…