首页 > Web开发 > 详细

JS查找孩子节点

时间:2014-03-05 07:22:01      阅读:598      评论:0      收藏:0      [点我收藏+]

          以前看了JS方面的书,如今用到了,书看得再多,不用就忘了,所以经常用用你所学到的知识,温故知新。

         

        

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<!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>

            还需要努力和实践,坚持,加油。

JS查找孩子节点,布布扣,bubuko.com

JS查找孩子节点

原文:http://www.cnblogs.com/xshang/p/3580759.html

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