亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

關于js里previousSibling 的問題

關于js里previousSibling 的問題

freefox 2016-04-06 10:58:44
<!DOCTYPE?HTML> <html> <head> <meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"> <title>nextSibling</title> </head> <body> <ul?id="u1">??? ????????????<li?id="a">javascript</li>??? ????????????<li?id="b">jquery</li>??? ????????????<li?id="c">html</li>??? ????????</ul>??? ????????<ul?id="u2">??? ????????????<li?id="d">css3</li>??? ????????????<li?id="e">php</li>??? ????????????<li?id="f">java</li>??? ????????</ul>??? <script?type="text/javascript"> ????function?get_nextSibling(n){ ????????var?x=n.nextSibling; ????????while?(x?&&?x.nodeType!=1){ ????????????x=x.nextSibling; ????????} ????????return?x; ????} ?????function?get_previousSibling(a) ????{ ????????var?o=a.previousSibling; ????????while?(o?&&?o.nodetype!=1) ????????{ ????????????o=o.previousSibling; ????????} ????????return?o; ????} ????var?x=document.getElementsByTagName("li")[0]; ????document.write(x.nodeName); ????document.write("?=?"); ????document.write(x.innerHTML); ???? ????var?y=get_nextSibling(x); ???? ????if(y!=null){ ????????document.write("<br?/>nextsibling:?"); ????????document.write(y.nodeName); ????????document.write("?=?"); ????????document.write(y.innerHTML); ????}else{ ??????document.write("<br>已經是最后一個節點");?????? ????} ???? ??? ???? ????var?a=document.getElementsByTagName("li")[2]; ????document.write("<br>"+a.nodeName); ????document.write("?=?"); ????document.write(a.innerHTML); ???? ????var?b=get_previousSibling(a); ???//?alert?(b.nodetype); ????if(b!=null){ ????????document.write("<br?/>nextsibling:?"); ????????document.write(b.nodeName); ????????document.write("?=?"); ????????document.write(b.innerHTML); ????} ????else{ ??????document.write("<br>已經是第一個節點");?????? ????} </script> </body> </html>代碼如上 為什么第60行 返回的是NULL,我一直弄不明白。
查看完整描述

1 回答

已采納
?
李曉健

TA貢獻1036條經驗 獲得超461個贊

function?get_previousSibling(a)?{
????var?o?=?a.previousSibling;
????while?(o?&&?o.nodeType?!=?1)?{???//nodeType?是大寫的?T
????????o?=?o.previousSibling;
????}
????return?o;
}


查看完整回答
反對 回復 2016-04-06
  • 1 回答
  • 0 關注
  • 1743 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號