- ·上一篇文章:HTMLCollection namedItem() 方法
- ·下一篇文章:HTMLCollection item() 方法
HTMLCollection length 属性
HTMLCollection length 属性 DOM HTMLCollection定义和用法length 属性返回 HTMLCollection 对象中元素的数量。该属性是只读的。该属性在循环 HTMLCollection 对象时很有用。语法HTMLCollection.length返回值返回一个数字,表示 HTMLCollection 对象中元素的数量。浏览器支持属性lengthYesYesYesYesYes实例实例循环输出所有 class="myclass 的元素并修改它们的背景颜色:var x = document.getElementsByClassName("myclass");for (i = 0; i < x.length; i++) {x.item(i).style.backgroundColor = "red";}尝试一下 ?相关文章HTMLCollection: item() 方法HTML Element: getElementsByClassName() 方法HTML Element: getElementsByTagName() 方法 DOM HTMLCollection
HTMLCollection length 属性