JS-Dom概念

來源:互聯網
上載者:User

標籤:alert   utf-8   document   win   har   doctype   content   nload   nod   

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>無標題文檔</title>
<script>
window.onload = function() {
 
 var oUl = document.getElementById(‘ul1‘);
 
 /*
  元素.childNodes : 唯讀 屬性 子節點列表集合
   標準下:包含了文本和元素類型的節點,也會包含非法嵌套的子節點
   非標準下:只包含元素類型的節點,ie7以下不會包含非法嵌套子節點
   
   childNodes只包含一級子節點,不包含後輩孫級以下的節點
  
  DOM節點的類型有很多種 12種
  
  元素.nodeType : 唯讀 屬性 當前元素的節點類型
  
  元素節點 : 1
  屬性節點 : 2
  文本節點 : 3
 */
 
 alert( oUl.childNodes.length );
 
 //alert( oUl.nodeType );
 
 //alert(oUl.childNodes[0].nodeType);
 
 //屬性
 // 元素.attributes : 唯讀 屬性 屬性列表集合
 
 //alert( oUl.attributes.length );
 
 //alert( oUl.attributes[0].nodeType );
 
 /*for (var i=0; i<oUl.childNodes.length; i++) {
  
  if ( oUl.childNodes[i].nodeType == 1 ) {
   oUl.childNodes[i].style.background = ‘red‘;
  }
  
 }*/
 
}
</script>
</head>

<body>
 <ul id="ul1" style="border: 1px solid red;">
        <li>11111 <span>span</span></li>
        <li>22222</li>
        <li>33333</li>
        <li>44444</li>
        <p>pppppppp</p>
    </ul>
</body>
</html>

JS-Dom概念

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.