2011-07-15 8 views
1

属性ノードがDOM内の子ノードとしてカウントされませんか?属性ノードはDOM2の子ノードとしてカウントされませんか?

私のページはこのように5体の子供です:テキスト> h1>テキスト> div>テキスト> // 5人の子供の末尾 attributnodesはカウントされませんか? childNodesプロパティは、すべてのタイプのノードの配列を返しますか?

function domTest() { 
    var le = document.body.childNodes.length; 
    alert(le);//alerts 5 children where are attribut nodes? 
    for(i = 0; i < le; i++) { 
     alert(document.body.childNodes[i].nodeType); 
     alert(document.body.childNodes[i].nodeName); 
     alert(document.body.childNodes[i].nodeValue); 
    } 
} 

window.onload = domTest; 
:このスクリプトで

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
     <title>DOM testing</title> 
     <script src="scripts/domTesting3.js" type="text/javascript" charset="utf-8"></script> 
    </head> 
    <body bgcolor="#cccccc"> 
     <h1 id="test">Test</h1> 
     <div id="content"> 
      <p>Examining the DOM2 Core and DOM2 HTML Recommendations</p> 
      <h2>Browsers</h2> 
      <ul id="browserList"> 
       <li id="chromeListItem"> 
        <a href="http://www.google.com/chrome/ "title="Get Chrome" id="chrome">Chrome</a> 
       </li> 
       <li id="firefoxListItem"> 
        <a href="http://www.getfirefox.com/"title="Get Firefox" id="firefox">Firefox 5.0</a> 
       </li> 
       <li> 
        <a href="http://www.microsoft.com/windows/ie/downloads/" title="Get Microsoft Internet Explorer" id="msie">Microsoft Internet Explorer 9</a> 
       </li> 
       <li> 
        <a href="http://www.apple.com/macosx/features/safari/" title="Check out Safari" id="safari">Safari</a> 
       </li> 
       <li> 
        <a href="http://www.opera.com/download/" title="Get Opera" id="opera">Opera 9</a> 
       </li> 
      </ul> 
     </div> 
    </body> 
</html> 

:テキスト>属性>テキスト> H1> attribut>テキスト> div>のattribut>テキスト> P //など...

で、私はこのページを持っています

答えて

0

AttrオブジェクトはNodeインタフェースを継承しますが、実際に記述されている要素の子ノードではないため、DOMはそれらをドキュメントツリーの一部と見なしません。したがって、Node属性parentNode、previousSibling、nextSiblingは、Attrオブジェクトのnull値を持ちます。

Attr interface description of DOM Level 2 Coreからです。

関連する問題