美文网首页
children----2019-01-10

children----2019-01-10

作者: 不2青年 | 来源:发表于2019-01-10 18:10 被阅读0次

    childNodes存在兼容性问题,children没有兼容性问题,用法基本一样。

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>1.2 children</title>
        <script>
            window.onload = function () {
                /* body... */
                var oUl = document.getElementById('ul1');
                /*
                    元素.children :只读属性 子节点列表集合
                    标准或非标准下都只包含元素节点
                */
                for(var i=0;i<oUl.children.length;i++){
                    oUl.children[i].style.background = 'red';
                }
            }                   
    
        </script>
    </head>
    <body>
        <ul id="ul1">
            <li>111</li>
            <li>222</li>
            <li>333</li>
            <li>444</li>
        </ul>
    </body>
    </html>
    

    相关文章

      网友评论

          本文标题:children----2019-01-10

          本文链接:https://www.haomeiwen.com/subject/xwzarqtx.html