<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title></head><body style="text-align:center" onload="init();"> <input type="text" /><br /><br /> <input type="text" /> <script type="text/javascript"> function init(){ var d=document.getElementsByTagName("input"); for(var i=0;i<d.length;i++){ d[i].onfocus=function(){ timer=setInterval(function(){ var c=this.style.borderColor; if(c=="yellow") { this.style.borderColor=""; } else { this.style.borderColor="yellow"; } },1000) } d[i].onblur=function(){ clearInterval(timer); this.style.borderColor=""; } } } </script></body></html>
2 回答
已采纳
stone310
TA贡献361条经验 获得超191个赞
中间focus事件函数修改如下注释:
d[i].onfocus=function(){ var self=this; //保存this,这里this指的是d[i] timer=setInterval(function(){ var c=self.style.borderColor; //用刚才保存的this值,因为这里的this值就是window,而不是d[i]了 if(c=="yellow") { self.style.borderColor=""; } else { self.style.borderColor="yellow"; } },1000) }
添加回答
举报
0/150
提交
取消