慕設(shè)計7041374
2016-06-13 11:40:43
Q1:這句 var oSubNav=this.getElementsByTagName('ul')[0]; 表達(dá)什么??Q2:if(oSubNav) 為什么可以判斷有沒有二級導(dǎo)航?<script>window.onload=function(){? ? var aLi=document.getElementsByTagName('li');for(var i=0; i<aLi.length; i++){? aLi[i].onmouseover=function(){? ? ? ? ? ? var oSubNav=this.getElementsByTagName('ul')[0];? ? ? ? ? ? if(oSubNav){? ? ? ? ? ? var This=oSubNav;? ? ? ? ? ? clearInterval(This.time);? ? ? ? ? ? This.time=setInterval(function(){? ? ? ? ? ? ? ? ? ? This.style.height=This.offsetHeight+16+"px";? ? ? ? ? ? ? ? ? ? if(This.offsetHeight>=120)? ? ? ? ? ? ? ? ? ? clearInterval(This.time);alert(This.time);? ? ? ? ? ? ? ? },30)? ? ? ? ? ? ?}? ? ? ? ? }? ? ? ? //鼠標(biāo)離開菜單,二級菜單動畫收縮起來。aLi[i].onmouseout=function(){? ? ? ? ? ? var oSubNav=this.getElementsByTagName('ul')[0];? ? ? ? ? ? if(oSubNav){? ? ? ? ? ? var This=oSubNav;? ? ? ? ? ? clearInterval(This.time);? ? ? ? ? ? This.time=setInterval(function(){? ? ? ? ? ? ? ? ? ? This.style.height=This.offsetHeight-16+"px";? ? ? ? ? ? ? ? ? ? if(This.offsetHeight<=0)? ? ? ? ? ? ? ? ? ? clearInterval(This.time);?? ? ? ? ? ? ? ? },30)? ? ? ? ? ? ?}? ? ? ? ? }}}</script>
5 回答

攻城頭獅
TA貢獻(xiàn)2條經(jīng)驗 獲得超3個贊
//當(dāng)你鼠標(biāo)離開li時觸發(fā)
aLi[i].onmouseout=function(){
????????????//this.getElementsByTagName('ul')是獲取這個li標(biāo)簽里面所有為ul的子元素,[0]是下標(biāo),指第一個元素
? ? ? ? ? ? var oSubNav=this.getElementsByTagName('ul')[0];//意思是獲取鼠標(biāo)離開的這個li里面的第一個ul
//........ }

剛毅87
TA貢獻(xiàn)345條經(jīng)驗 獲得超309個贊
Q1:getElementsByTagName 獲取的是一個數(shù)組
????this.getElementsByTagName('ul')[0]的意思是獲取所有的 ul賦值為一個數(shù)組,取數(shù)組的第一個值
Q2:if(oSubNav)應(yīng)該等價于 if(oSubNav == true),具體如何判斷,不看具體代碼,不清楚
添加回答
舉報
0/150
提交
取消