為什么我寫(xiě)前一個(gè)節(jié)點(diǎn)就是不顯示呢?
<script type="text/javascript">
? ? function get_nextSibling(n){
? ? ? ? var x=n.nextSibling;
? ? ? ? while (x && x.nodeType!=1){
? ? ? ? ? ? x=x.nextSibling;
? ? ? ? }
? ? ? ? return x;
? ? }
? ? var x=document.getElementsByTagName("li")[1];
? ? 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>已經(jīng)是最后一個(gè)節(jié)點(diǎn)"); ? ? ?
? ? }
? ?
? ? var i=get_previousSibling(x);
? ??
? ? if(i!=null){
? ? ? ? document.write("<br />nextsibling: ");
? ? ? ? document.write(i.nodeName);
? ? ? ? document.write(" = ");
? ? ? ? document.write(i.innerHTML);
? ? }else{
? ? ? document.write("<br>已經(jīng)是最后一個(gè)節(jié)點(diǎn)"); ? ? ?
? ? }
? ? ? ? ? ?
2016-04-01
?? var i=get_previousSibling(x); ?你就沒(méi)這個(gè)函數(shù),這是執(zhí)行的什么?
2016-04-01
要想顯示著一塊
?var i=get_previousSibling(x);
? ??
? ? if(i!=null){
? ? ? ? document.write("<br />nextsibling: ");
? ? ? ? document.write(i.nodeName);
? ? ? ? document.write(" = ");
? ? ? ? document.write(i.innerHTML);
? ? }else{
? ? ? document.write("<br>已經(jīng)是最后一個(gè)節(jié)點(diǎn)"); ? ? ?
? ? }
的內(nèi)容,需要,你要執(zhí)行的函數(shù)體get_previousSibling(x);這個(gè)函數(shù):
function get_previousSibling(n){
var x=n.previousSibling;
while(x.nodeType!=1){
x=x.previousSibling;
}
return x;
}
注意:這個(gè)get_previousSibling名字,可以隨便寫(xiě),比如,function aa(n){函數(shù)體},那么你在用到這個(gè)函數(shù)時(shí)間,var i=get_previousSibling(x);這里,需要改成,var i=aa(x);
2016-04-01
不知道你在問(wèn)什么