為什么我寫前一個節點就是不顯示呢?
<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>已經是最后一個節點"); ? ? ?
? ? }
? ?
? ? 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>已經是最后一個節點"); ? ? ?
? ? }
? ? ? ? ? ?
2016-04-01
?? var i=get_previousSibling(x); ?你就沒這個函數,這是執行的什么?
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>已經是最后一個節點"); ? ? ?
? ? }
的內容,需要,你要執行的函數體get_previousSibling(x);這個函數:
function get_previousSibling(n){
var x=n.previousSibling;
while(x.nodeType!=1){
x=x.previousSibling;
}
return x;
}
注意:這個get_previousSibling名字,可以隨便寫,比如,function aa(n){函數體},那么你在用到這個函數時間,var i=get_previousSibling(x);這里,需要改成,var i=aa(x);
2016-04-01
不知道你在問什么