页面代码如下:
<div id='a'>AAA</div>
<div id='b'>BBB</div>
<div id='c'>CCC</div>
<div id='d'>DDD</div>
要求:
当鼠标放在某个div上3秒不移出,则弹出一个提示框,把div里的内容提示出来,
如果鼠标划过一个div或在div上停留的时间没有3秒则不弹出对话框提示。
知道的大家互相学习下,要详细点,请不要只说简单的几个字,谢谢!
<div id='a'>AAA</div>
<div id='b'>BBB</div>
<div id='c'>CCC</div>
<div id='d'>DDD</div>
要求:
当鼠标放在某个div上3秒不移出,则弹出一个提示框,把div里的内容提示出来,
如果鼠标划过一个div或在div上停留的时间没有3秒则不弹出对话框提示。
知道的大家互相学习下,要详细点,请不要只说简单的几个字,谢谢!
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
window.onload=function(){
var timer,div1=document.getElementById("show");
div1.onmouseover=function(){
timer=setTimeout(function(){document.getElementById("content").style.display='block'},3000);
}
div1.onmouseout=function(){
clearTimeout(timer);
document.getElementById("content").style.display='none';
}
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<div id="show" style="width:100px;height:50px;border:1px solid gray">
<div id="content" style="display:none">显示内容</div>
</div>
</BODY>
</HTML>
<head>
<style type="text/css">
<!--
#a { position:absolute; width:200px; height:100px; top:0px; left:0px; background:none repeat scroll 0 0 #f7fcff; border:1px solid #a1cdec;}
#b{ position:absolute; width:200px; height:100px; top:100px; left:0px; background:none repeat scroll 0 0 #f7fcff; border:1px solid #a1cdec;}
#c{ position:absolute; width:200px; height:100px; top:200px; left:0px; background:none repeat scroll 0 0 #f7fcff; border:1px solid #a1cdec;}
#d { position:absolute; width:200px; height:100px; top:300px; left:0px; background:none repeat scroll 0 0 #f7fcff; border:1px solid #a1cdec;}
-->
</style>
</head>
<body>
<div id="a" onmouseout="func_mout();" onmouseover="func_mover();">AAA</div>
<div id="b" onmouseout="func_mout();" onmouseover="func_mover();">BBB</div>
<div id="c" onmouseout="func_mout();" onmouseover="func_mover();">CCC</div>
<div id="d" onmouseout="func_mout();" onmouseover="func_mover();">DDD</div>
<script>
var t;
function func_mover()
{
t = setTimeout("f()","3000");
}
function f()
{
alert("123");
}
function func_mout()
{
clearTimeout(t);
}
</script>
</body>
</html>
{
HTMLElement.prototype.contains = function(obj)
{
while(obj && obj.tagName)
{
if(obj == this)
return true;
obj = obj.parentNode;
}
return false;
};
} var $ = function (id,obj) {
return 'string' == typeof(id) ? (obj||document).getElementById(id) : id;
};
var timer;
window.onload=function(){
var div=$("div1");
div.onmouseover=function(){var o=this;timer= setTimeout(function(){alert(o.innerHTML);},3000);};
div.onmouseout=function(e){
e = e||event;
e = e.toElement || e.relatedTarget ; // IE toElement FF:relatedTarget
if(typeof(e)!="undefined" &&!this.contains(e)){clearInterval(timer);
}
};
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head> <body>
<div id='a'>AAA</div>
<div id='b'>BBB</div>
<div id='c'>CCC</div>
<div id='d'>DDD</div>
<div id="tip" style="display:none;border:1px solid #ddd;padding:10px;"></div>
<script type="text/javascript">
<!--
function $(id){return document.getElementById(id)};
(function(){
var timer = null,tip = $('tip');
for(var i=0;i<arguments.length;i++){
var el = $(arguments[i]);
el.onmouseover = function(){
clearTimeout(timer);
var _this = this;
timer = setTimeout(function(){
tip.style.display = 'block';
tip.innerHTML = _this.innerHTML;
},3000);
}
}
tip.onmouseout = function(){this.style.display = 'none';}
})('a','b','c','d');
//-->
</script>
</body>
</html>