下面這段代碼不懂啊,求解答啊,var _this=this.getElementsByTagName('i')[0];
window.inload=function(){
var oMove=document.getElementById('move');
var aList=oMove.getElementsByTagName('a');
for(var i=0;i<aList.length;i++){
aList[i].onmouseover=function(){
var _this=this.getElementsByTagName('i')[0];
startMove(_this,{top:-25,opacity:0},function(){
_this.style.top=30+'px';
startMove(_this,{top:25,opacity:100})
});
}
}
}
以上這段是老師的代碼
for(var i=0;i<aList.length;i++){}
這個是遍歷所有取到的a標簽,所以獲得的是一個數組,所以有了接下來的:
aList[i].onmouseover=function(){}
但是接下來的var _this=this.getElementsByTagName('i')[0];我不是很懂,為什么這里在當前事件下,還要取第一個標簽呢?
當i=1時,那么得到aList[1].onmouseover=function(){},也就是第二個a標簽,這個時候為什么還要取
var _this=this.getElementsByTagName('i')[0],這里取到的不是第一個i標簽嗎,但是我們現在要的難道不是第二個i標簽嗎,不懂,求解答。。。
2016-08-22
這快我也有問題,不過看了你們的解釋之后貌似明白了,首先都是用的getElementsByTagName所以這獲得都是一個數組,無論這個數組有多少元素,哪怕一個,他也是數組,回到樓主的問題當中,因為都是用的數組,所以要獲取對象都是用[0]的,拙見。
2016-04-26
當i=0 時,aList[i] 取到的是第一個 a 標記. ?
這個時候 ?var?_this=this.getElementsByTagName('i')[0]; ?中的_this 指的是第一個a中的 i 標記.
當i=1 時,aList[i] 取到的是第二個 a 標記. ?
這個時候 ?var?_this=this.getElementsByTagName('i')[0]; ?中的_this 指的是第二個a中的 i 標記.
并不是第一個i標記. ?
注意?var?_this=this.getElementsByTagName('i')[0]; ? 這里面是this.getElementsByTagName('i')[0] ?而不是document.getElementsByTagName('i')[0]. 兩者取到的是不同的,后者取到的是整個文檔中的i的第一個
前者是 this下的i的第一個,也就是第 i 個a中的 i標記的第一個.
2016-04-25
getElementsByTagName 這個方法返回一個類似數組的對象,訪問數組對象可以用下標來訪問
【0】就是取其第一項,(注意是elements 那個S 說明是個數組類的)
getElementsByTagName返回的是一個集合。[0],表示獲取傳進來元素里面元素叫i的。