首页 > 其他 > 详细

DOM

时间:2017-06-16 22:53:29      阅读:262      评论:0      收藏:0      [点我收藏+]

子节点

<!DOCTYPE html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <title>Document</title>
 </head>
 <script type="text/javascript">
  window.onload=function(){
   var ou=document.getElementById(‘ul1‘)
   // console.log(ou.childNodes.length)
   // childNodes包括文本节点、元素节点
   // alert(ou.childNodes.length)
   // alert(ou.children.length)  --- 常用   
    
   for (var i = ou.childNodes.length - 1; i >= 0; i--) {
    // nodeType==3 ->  文本节点
    // nodeType==1 ->  元素节点
    // alert(ou.childNodes[i].nodeType) 
    if(ou.childNodes[i].nodeType==1){
     ou.childNodes[i].style.background=‘red‘
    }
   }
  }
 </script>
 <body>
  <!-- dom基础 -->
  <ul id="ul1">
   <li>我是元素节点</li>
   <li></li>
   <li></li>
   <li></li>
   <li></li>
  </ul>
  我是文本节点
 </body>
</html>


DOM

原文:http://f1yinsky.blog.51cto.com/12568071/1939095

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!