屬性
Attribute 會擴充套件一個 HTML 或 XML 元素,改變其行為或提供元資料。
Attribute 的形式始終是 name="value"(attribute 的識別符號後跟其關聯的值)。您可能會看到沒有等號或值的 attribute。在 HTML 中,這是一種提供空字串的簡寫。但是,這在 XML 中是無效的:XML 要求所有 attribute 都必須有一個顯式值。
許多 HTML attribute 是 布林 attribute。這些 attribute 的值僅由 attribute 的存在與否來控制。有關更多資訊,請參閱 布林 attribute。
Attribute 的反射
Attribute 可能會被反射到特定介面的特定屬性中。
這意味著 attribute 的值可以透過相應介面上的屬性直接在 JavaScript 中讀取或寫入,反之亦然。反射屬性比使用 Element 介面的 getAttribute() 和 setAttribute() 方法來獲取和設定 attribute 提供了一種更自然的程式設計方法。
有關更多資訊,請參閱 Attribute 反射。
另見
- HTML 屬性參考
- 屬性反映
- 有關 HTML 的 全域性 attribute 的資訊
- XML StartTag Attribute Recommendation in W3C XML Recommendation
- 相關詞彙表術語