日期:2014-05-16  浏览次数:20454 次

previousSibling
<HTML>      
    <HEAD>          
    <STYLE       type= "text/css ">    
.g{top:0px;}

    </HEAD>      
    <body>      
    <form>      
    <div   id= "d "   class= "g "> </div>      
<input   id= "c "   class= "g "> </input>
    <DIV   id= "b "   class= "g ">
    </DIV>
<DIV   id= "a "   class= "g ">
    </DIV>  
<script>
    alert(document.getElementById( "b ").previousSibling.id);//为什么是undefined
</script>
    </form>      
    </body>      
    </HTML>

------解决方案--------------------
中间不要有回车等特殊字符
<input id= "c " class= "g "> </input> <DIV id= "b " class= "g ">
------解决方案--------------------
就是挺奇怪的????
为什么加了回车后,它把 回车符号,认为了一个 NODE ??
下面的语句就可以得到 c
alert(document.getElementById( "b ").previousSibling.previousSibling.id);

但是对于都是 <DIV> </DIV> 的标签组,就没有问题呢???
------解决方案--------------------
回车换行也是文本,当然算元素了
------解决方案--------------------
反正要用previousSibling我就觉得两个无素中间什么东西也没有才靠得住。