JS查找孩子節點


          以前看了JS方面的書,如今用到了,書看得再多,不用就忘了,所以經常用用你所學到的知識,溫故知新。

         

        

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>###</title>
<meta keywords="商品目錄"/>
<meta description="JS查找孩子節點"/>
<script type="text/javascript">
     
     function getContent()
     {
      var x=document.getElementById("content");
      for(var i=0;i<x.childNodes.length;i++)
      {
          if((content=x.childNodes[i].innerHTML)=="目錄")
          {
            var next=x.childNodes[i].nextSibling.nextSibling.textContent;
            alert(next);
          }
      }
       
     }
     window.onload=getContent;
</script>
</head>
<body>
<div id="content">
<h3>商品</h3>
<div id="1">
  <p >this is the first paragragh</p>
</div>
<h3>作者</h3>
<div id="2">
  <p>this is the second paragragh</p>
</div>
<h3>目錄</h3>
<div id="3">
  <p>this is the third paragragh</p>
</div>
</div>
</body>
</html>

            還需要努力和實踐,堅持,加油。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM