你那个DIV里,用onmouseout事件控制:
<div id=mydiv onmouseout='javascript:hideDiv();'>然后在hideDiv()里搞些document.getElementById("mydiv").style.display="none"一类的语句
<div id=mydiv onmouseout='javascript:hideDiv();'>然后在hideDiv()里搞些document.getElementById("mydiv").style.display="none"一类的语句
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script>
</script>
<body>
<div id="div1" style="background-color:#FF00FF; width:200px; height:100px; display:none;" ></div>
<span onmouseover="document.getElementById('div1').style.display=''">文字</span>
</body>
</html>
触碰到文字就显示这个不难,只是如果你是要表单或者div在上面出现,其他内容向下,这是鼠标很可能会离开了文字。如果是想鼠标离开表单或者div时隐藏表单或者div,在div那里加上onmouseout="this.style.display='none'"
change--》 onmouseout
鼠标移动到此触发事件 onmousemove 或者 onmouseover
鼠标移开触发事件 onmouseout将触发事件的文字处,onclick="a();" 换成 onmousemove="a();" onmouseout="b();";function a() {
//顶部Div显示方法
document.getElementById("顶部Div的id").style.display = 'block';
}function b() {
//顶部Div隐藏方法
document.getElementById("顶部Div的id").style.display = 'none';
}
<!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=gb2312" />
<title>无标题文档 </title>
</head>
<script>
</script>
<body>
<div id="div1" style="background-color:#FF00FF; width:200px; height:100px; display:none;" onmouseout="this.style.display='none'" onmouseover="document.getElementById('div1').style.display='block'">222222222222 </div>
<span onmouseover="document.getElementById('div1').style.display='block'" onmouseout="document.getElementById('div1').style.display='none'">文字 </span>
</body>
</html>在此感谢2楼
把简单问题复杂化了吧。。