window.onload=function(){ var aA=document.getElementsByTagName("a"); for(var i=0;i<aA.length;i++){ aA[i].onmouseover=function(){ clearInterval(this.time); var This=this; This.time=setInterval(function(){ This.style.width=This.offsetWidth+8+"px"; if(This.offsetWidth>=120){ clearInterval(This.time); } },30) } aA[i].onmouseout=function(){ clearInterval(this.time); var This=this; This.time=setInterval(function(){ This.style.width=This.offsetWidth-8+"px"; if(This.offsetWidth<=100){ This.style.width="100px"; clearInterval(This.time); } },30) } }}这段代码中,this.time是什么意思? 还有为啥要定义This?
3 回答

zhangcl
TA贡献12条经验 获得超7个赞
This就是你当前的页面,应该是window,time是setInteval()这个函数的返回值,是一个数字,你可以在百度上查到的,表示这个函数用window的time变量来接收。同理可以停止setInteval()的操作,方法我忘记了 ,你可以查一下,好像是clearInteval(),然后将time=null就行了;

李晓健
TA贡献1036条经验 获得超461个赞
var This=this; 是为了保存当前鼠标所在的标签, This.time=setInterval(function() 是给当前标签添加一个和time属性,用来保存应用到这个标签上的定时器。 定时器里面的 clearInterval(This.time); 是取消这个标签上的定时器。这里用This而不用 this是因为,这里的this已经不是鼠标所在有标签了,而This在上面已经定义成是当前标签。
添加回答
举报
0/150
提交
取消