A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://developer.mozilla.org/zh-CN/docs/Web/API/HTMLCollection/length below:

HTMLCollection.length - Web API | MDN

HTMLCollection.length

Baseline Widely available

HTMLCollection.length 属性返回 HTMLCollection 中的元素数量。

值

一个正整数,表示 HTMLCollection 中元素的数量。

示例

length 属性在 DOM 编程中通常很有用。它通常用于测试集合的长度,去看它是否真的存在。它也通常用于 for 循环中的迭代器,如下示例。

// All the elements with the class ".test" in the document
var items = document.getElementsByClassName("test");

// For each test item in the list,
// append the entire element as a string of HTML
var gross = "";
for (var i = 0; i < items.length; i++) {
  gross += items[i].innerHTML;
}

// gross is now all the HTML for the test elements
规范 浏览器兼容性

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4