在某一控件上鼠标停两秒,就提示信息,
我是这样写的
function showAlert() {
window.setTimeout("fun('hello')",2000);
}
function fun(a) {
alert(a);
}
onmouserover="showAlert()"
但是问题是,鼠标一停在上面再移开过两秒后就会显示,我要的效果是鼠标静止在控件上两秒就显示,如果两秒内离开了,就不显示,请高手指点一下
我是这样写的
function showAlert() {
window.setTimeout("fun('hello')",2000);
}
function fun(a) {
alert(a);
}
onmouserover="showAlert()"
但是问题是,鼠标一停在上面再移开过两秒后就会显示,我要的效果是鼠标静止在控件上两秒就显示,如果两秒内离开了,就不显示,请高手指点一下
var TIMER;
function showAlert() {
TIMER = window.setTimeout("fun('hello')",2000);
}
function fun(a) {
alert(a);
clearTimeout(TIMER )
}
<script type="text/javascript">
<!--
var timer = null;
function showAlert(msg){
timer = setTimeout(function(){fun('a')}, 2000);
}
function fun(msg){
alert(msg)
}
//-->
</script>
<div style='width:100px;height:100px;background-color:red' onmouseover='showAlert("")' onmouseout="clearTimeout(timer)"></div>