当前位置:K88软件开发文章中心编程全书编程全书03 → 文章内容

HTMLCollection length 属性

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-14 5:03:40

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 属性