CSSStyleDeclaration.item()
CSSStyleDeclaration.item() 通过下标从 CSSStyleDeclaration 返回一个 CSS 属性值。只要传入参数这个方法就不会抛出异常;当传入的下标越界时会返回空字符串,当未传入参数时会抛出一个 TypeError 。
语法
var propertyName = style.item(index);
参数
index是需要查找节点的索引,索引下标从零开始。
Return value
propertyName是一个DOMString,是在特定索引位置下的属性的名称。
使用以下的 javascript 语法可以通过索引从 style 的节点列表中获取对应值:
var propertyName = style[index];
范例
js
var style = document.getElementById('div1').style;
var propertyName = style.item(1); // or simply style[1] - returns the second style listed
规范
| Specification | 
|---|
| CSS Object Model (CSSOM)  # dom-cssstyledeclaration-item  | 
浏览器兼容性
BCD tables only load in the browser