alert和onblur死循环
点击文本框触发聚焦事件,弹出警告框,然后点击警告框中中的确定,其实焦点已经移动到警告框,触发失焦事件了,确定后焦点又会回到文本框,又会触发聚焦事件,形成循环。因此alert()不应该与焦点事件一起使用。
<script type="text/javascript">
window.onload=function(){
var text1=document.getElementById("text1");
text1.onfocus=function(){
alert("聚焦事件触发");
}
text1.onblur=function(){
alert("失焦事件触发");
}
}
</script>
</head>
<body>
<input type="text" id="text1"/>
</body>
原文链接:焦点事件