加入鏈?zhǔn)絼赢嫷拇a后會出現(xiàn)一個問題?:多1.js:21 Uncaught TypeError: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.
錯誤提示加了注釋的2行有問題!
只能有第一個動畫,第二個無法進(jìn)行。錯誤一直累計。百度沒找到解決方法,求教!
op.onmouseover=function(){yd(this,"height",300,function(){yd(this,"width",400);});}
op.onmouseout=function(){yd(this,"height",150,function(){yd(this,"width",200);});}
function getStyle(obj,attr)
{
if(obj.currentStyle){return obj.currentStyle[attr];}
//else { return getComputedStyle(obj,false)[attr];}
}
//iccr=parseInt(getStyle(obj,attr));
2017-04-30
我猜是this的的作用域問題,onmouseover內(nèi)的function函數(shù)應(yīng)該把this傳參,因為第二個function中的this不再指向op本身。相關(guān)的this 問題我也不太明白,正學(xué)習(xí)
應(yīng)改為
op.onmouseover = function() {
var that = this //將this傳參
yd(that, "height", 300, function() {
yd(that,"width",400); });
}
不知道對不對,共勉。
2018-12-16
謝謝你,我想起來了,