<input type="button" id="btn" value="btn"/>
<div id="div1" style="display:none;">I am tooltip</div>
<script language="JavaScript">
<!--
// 方法A
var obj = {
flag : null,
setTime : function(n) {
this.flag = setTimeout(function(){
document.getElementById("div1").style.display = "";
}, n);
},
clear : function() {
clearTimeout(this.flag);
document.getElementById("div1").style.display = "none";
}
}
document.getElementById("btn").onmouseover = function() {obj.setTime(1000);};
document.getElementById("btn").onmouseout = function() {obj.clear();};
//-->
</script>
<script language="JavaScript">
<!--
//方法B
//var flag;
//function setTime(time) {
// return(function(e){
// flag=setTimeout(function() {
// document.getElementById("div1").style.display = "";
// }, time);
// });
//}
//function clear() {
// clearTimeout(flag);
// document.getElementById("div1").style.display = "none";
//}
//
//document.getElementById("btn").onmouseover = setTime(1000);
//document.getElementById("btn").onmouseout = clear;
//-->
</script>
总觉得方法A和方法B都存在泄露隐患。。。