CSSStyleDeclaration item() 方法

CSS CSSStyleDeclaration CSS CSSStyleDeclaration

實例

返回 id 為 ex1 元素對應樣式的第一個屬性名:

var style = document.getElementById("ex1").style; var propname = style.item(0); alert(propname);


定義和使用

item() 方法返回 CSS 樣式中指定索引位置的屬性名,索引值從 0 開始。


流覽器支持

方法
item() Yes 9.0 Yes Yes Yes

語法

style.item(index)

屬性值

參數 描述
index 必需。一個數字,代碼 CSS 樣式屬性的索引位置。

技術細節

DOM 版本: CSS Object Model
返回值: 字串, 表示屬性名。

更多實例

實例

迴圈輸出元素的所有樣式的屬性名:

for (i = 0; i < elmnt.style.length; i++) { txt += elmnt.style.item(i) }

CSS CSSStyleDeclaration CSS CSSStyleDeclaration