玩笑过后

导航

Comment类型

注释在DOM中是通过Comment类型来表示的。

nodeType  8

nodeName  #Comment

nodeValue  注释的内容

parentNode  可能是Document或Element

 不支持子节点

Comment类型和Text类型继承自相同的基类,所以他拥有除了splitText()之外的所有字符串操作方法;

document.createComment('注释内容');  //创建一个注释节点

<script>
        var comment = document.createComment('这是注释');
        document.body.appendChild(comment);
        var len = document.body.childNodes.length;
        var arr = [];
        //console.log(document.childNodes[0]);
        for (var i=0;i<len;i++)
        {
            if (document.body.childNodes[i].nodeType === 8)
            {
                arr[arr.length] = document.body.childNodes[i];
            }
        }
        console.log(arr[0].__proto__);
    </script>

 

posted on 2018-08-16 14:55  玩笑过后  阅读(200)  评论(0编辑  收藏  举报