百度谷歌搜索了下 nodeType 2是属性节点  可是我用chrome测试 却怎么也出不来2  
比如<a href="www.test.com"></a>  的href应该是属性节点吧   可是就是测不出来  这个属性节点到底是什么呢

解决方案 »

  1.   

    <div id="a"><a href="www.test.com"></a></div>document.getElementById("a").childNodes[0].nodeType 试试
      

  2.   


    <script>
    window.onload = function(){
    var xml = new ActiveXObject("Msxml2.DOMDocument")
    xml.loadXML("<a href=\"www.test.com\"></a>");
    node = xml.selectSingleNode("//a/@href");
    alert(node.nodeType); //2
    }
    </script>
      

  3.   

    <a id="link1" href="www.test.com"></a>
    <script>
    var a = document.getElemntById('link1');
    var href = a.getAttributeNode('href');
    alert(href.nodeType)
    </script>
      

  4.   

    也就是说在html中childNodes里遍历的节点 不可能会出现nodeType=2 先找到元素节点燃后getAttributeNode才可以找得到 是吗????
      

  5.   

    XML结构里才有属性节点 html加载成xml attribute被解析成attributeNode
    应该这样理解吧
      

  6.   

    其实这个基本没什么用,nodeType有用到的话都是1和3。
      

  7.   

    对的,childNodes只包含元素节点和文本节点,不包含属性节点。