类数组对象HTMLCollenction

类数组对象HTMLCollenction


类数组对象HTMLCollenction

类数组对象HTMLCollenction

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="js/domready.js"></script><!--必须导入该文件,搜狗输入domready.js-->
    <script>
        myReady(function(){
            //以下是HTMLCollection类数组对象//
            //var scripts=document.scripts;
            //console.log(scripts);//返回:HTMLCollection(2) [script, script]
            //var links=document.links;
            //console.log(links);//返回:HTMLCollection(10) [a, a#onea, a, a, a, a, a, a, a, a, onea: a#onea]
            //var images=document.images;
            //console.log(images);//返回:HTMLCollection(2) [img, img]
            //var forms=document.forms;
            //console.log(forms);//返回:HTMLCollection(2) [form, form]
            //var cells=document.getElementById("tr").cells;
            //console.log(cells);//返回:HTMLCollection(3) [td, td, td](火狐)
            //var options=document.getElementById("city").options;
            //console.log(options);//返回:HTMLOptionsCollection(5) [option, option, option, option, option, selectedIndex: 0]
            //var ps=document.getElementsByTagName("p");
            //console.log(ps);//返回:HTMLCollection(3) [p, p, p]
            
            //var cells=document.getElementById("tr").cells;
            //console.log(cells);//返回HTMLCollection类数组对象:HTMLCollection(3) [td#td, td, td, td: td#td](谷歌)
            //console.log(cells.length);
            //console.log(cells.item(2));
            //console.log(cells.item(3));//超过类数组对象的长度时,显示为null
            //console.log(cells.namedItem("td"));//返回 cells 类数组中先查找 >厦门</option>
        </select>
        <p>基础挤出机会</p>
        <p>基础挤出机会</p>
        <p>基础挤出机会</p>
    </div>
</body>

==============

NodeList实例对象是一个类数组对象,它的成员是节点对象,包括childNodes和querySelectorAll()方法返回值

NamedNodeMap 会自我更新。如果在节点列表或 XML 文档中删除或添加一个元素,那么该列表将会自动更新

HTMLCollection集合包括getElementsByTagName()、getElementsByClassName()、getElementsByName()等方法的返回值,以及children、document.links、document.forms等元素集合