关于调用函数外加function()
在没有精简参数的时候做了如下尝试:
window.onload=function(){
var big=document.getElementById('big');
big.onmouseover=fnmove(10,0);
big.onmouseout=fnmove(-10,-300);
}
var timer=null;
function fnmove(speed,target){
clearInterval(timer);
var big=document.getElementById('big');
timer=setInterval(function(){
if(big.offsetLeft==target)
clearInterval(timer);
else
big.style.left=big.offsetLeft+speed+'px';},30)
}
我这样写效果出不来,而只有按老师的方式写成以下形式才能出现效果。(即在调用函数前加上function())
big.onmouseover=function(){fnmove(10,0);}
big.onmouseout=function(){fnmove(-10,-300);}
求问大神为什么?