怎么讓第二個this指向oLi[i]呢。熟悉this的還望指示
??????? window.onload=function()
??????? {
??????????? var oLi=document.getElementsByTagName('li');
??????????? for(var i=0,l=oLi.length;i<l;i++)
??????????? {
??????????????? oLi[i].timer=null;
??????????????? oLi[i].speed=0;
??????????????? oLi[i].icur=0;????????????? ?
??????????????? oLi[i].onmouseover=function()
??????????????? {
??????????????????? startmove(this,'width',400,function()
??????????????????????? {
??????????????????????????? startmove(this,'height',200);//就是這個this,換做oLi[i]也不行。
??????????????????????? });
??????????????? }
??????????? }
??????? }
2016-12-19
你之前在里面的函數中的this是指向外層的startmove的,所以直接寫this是取不到obj本身的,而外層的this是指向obj本身,把這個this存到一個變量里,作為參數傳到里面的函數就可以了
2017-01-03
this是? 函數在作為方法被調用時所處的對象
第一個startMove被調用時? 在Li1.onmouseover(){}中?? 于是this為Li1
但是?? 第二個被調用時 你如果用this??? 所處的對象就不是Li1了
所以第一個動作執行完? Li1就不會動
2016-12-19
window.onload = function () {
var oLi = document.getElementsByTagName('li');
for (var i = 0, l = oLi.length; i < l; i++) {
oLi[i].timer = null;
oLi[i].speed = 0;
oLi[i].icur = 0;
oLi[i].onmouseover = function () {
var that = this;
startmove(this, 'width', 400, function () {
startmove(that, 'height', 200); //就是這個this,換做oLi[i]也不行。
});
}
}
}
//寫錯了,是這樣子
2016-12-19
window.onload = function () {
var oLi = document.getElementsByTagName('li');
for (var i = 0, l = oLi.length; i < l; i++) {
oLi[i].timer = null;
oLi[i].speed = 0;
oLi[i].icur = 0;
oLi[i].onmouseover = function () {
startmove(this, 'width', 400, function () {
var that = this;
startmove(that, 'height', 200); //就是這個this,換做oLi[i]也不行。
});
}
}
}
//隨便寫的沒試驗,你試試