<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<html> 
  <head> 
    <title>functionDemo.html</title> 
 
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> 
    <meta http-equiv="description" content="this is my page"> 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"> 
 
  </head> 
 
  <body> 
 
  <script type="text/javascript"> 
        window.onload = function(){ 
                var objNodes = document.getElementById("divid"); 
                var nextNode = objNodes.nextSibling; 
                getNodeInfo(nextNode); 
        } 
         
        function getNodeInfo(node){ 
                alert("name:"+node.nodeName+"...type:"+node.nodeType+"...value:"+node.nodeValue); 
        } 
 
   </script> 
  <input type="button" value="yanshi" /><br /> 
  <input type="text" id="textid" value="sdfs"/> 
  <div id="divid"> 
        dsafsadfsadfasf 
  </div> 
  <p> 
  sdfsdfsfsdf 
  </p> 
  </body> 
</html> 
在听完毕老师的课时我做这个练习测试nextSibling,根据毕老师将的,这段代码应alert p标签,但是我测试alert的确是文本节点(ie10)。 
后来我考虑到可能是浏览器版本导致的,所以切换为ie8,ie9测试都alert了p标,所以nextSibling在ie10中会找标签之间的空行文本节点,在ie8和ie9中不会找这个空行文本节点。 
希望能帮到朋友们。 
 
 
 
 
 
 
 |