你那个DIV里,用onmouseout事件控制:
<div id=mydiv onmouseout='javascript:hideDiv();'>然后在hideDiv()里搞些document.getElementById("mydiv").style.display="none"一类的语句

解决方案 »

  1.   

    <!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;" ></div>
    <span onmouseover="document.getElementById('div1').style.display=''">文字</span>
    </body>
    </html>
    触碰到文字就显示这个不难,只是如果你是要表单或者div在上面出现,其他内容向下,这是鼠标很可能会离开了文字。如果是想鼠标离开表单或者div时隐藏表单或者div,在div那里加上onmouseout="this.style.display='none'"
      

  2.   

    http://blog.csdn.net/APOLLO_TS/archive/2008/12/27/3622507.aspx
    change--》 onmouseout
      

  3.   

    兄弟,功能你已经做好了,就是调用功能的触发方式没用对。鼠标点击触发事件 onclick
    鼠标移动到此触发事件 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';
    }
      

  4.   

    不太会JS,建议你用jquery吧;
      

  5.   

    改进了下2楼的代码,无论是从文字离开,还是从头部表单离开,头部都会隐藏:
    <!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楼
      

  6.   

    可以用DIV+CSS实现的功能,干嘛要用JS,
    把简单问题复杂化了吧。。