<!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>
<style>
div{
margin:120px;
}
#div1{
width:50px;
height:50px;
background:#666;
}
#div2{
display:none;
background:#888;
width:250px;
height:120px;
}
</style>
<script>
window.οnlοad=function(){
var oDiv1=document.getElementById('div1'),
oDiv2=document.getElementById('div2'),
timer = null;
oDiv2.οnmοuseοver=oDiv1.οnmοuseοver=function(){
clearTimeout(timer);
oDiv2.style.display="block";
}
oDiv1.οnmοuseοut=oDiv2.onmouseout = function(){ //这样写是为了节省代码用双等于
timer=setTimeout(function(){
oDiv2.style.display="none";
},500);
//oDiv2.style.display="none";
}
}
</script>
</head>
<body>
<div id="div1"></div>
<div id="div2"></div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
div{
margin:120px;
}
#div1{
width:50px;
height:50px;
background:#666;
}
#div2{
display:none;
background:#888;
width:250px;
height:120px;
}
</style>
<script>
window.οnlοad=function(){
var oDiv1=document.getElementById('div1'),
oDiv2=document.getElementById('div2'),
timer = null;
oDiv2.οnmοuseοver=oDiv1.οnmοuseοver=function(){
clearTimeout(timer);
oDiv2.style.display="block";
}
oDiv1.οnmοuseοut=oDiv2.onmouseout = function(){ //这样写是为了节省代码用双等于
timer=setTimeout(function(){
oDiv2.style.display="none";
},500);
//oDiv2.style.display="none";
}
}
</script>
</head>
<body>
<div id="div1"></div>
<div id="div2"></div>
</body>
</html>