onmouseout的时候只要移出去就消失了,我想在页面其他位置点击时再小时,而且,onmouseout的时候,如果我把鼠标移到div上的一个button或者textfield上,hide()方法也被调用,这是为什么呢.

解决方案 »

  1.   

    onmouseout="theDiv.style.display='none'";
      

  2.   

    <script language="JavaScript">
    document.onclick = function() {
      o = event.srcElement;
      if (o.id != "theDiv") {
        o.style.visibility = "hidden";
      }
    }
    </script><body><div style="border: 1px solid balck" id="theDiv">
    wokao 
    wokao a </div></body>
      

  3.   

    try this...<html>
    <head>
    <script language="JavaScript">
      function div_out() {
         var eTo = window.event.toElement;
         if (theDiv && eTo && !theDiv.contains(eTo)) 
               document.all.theDiv.style.display="none";
      }
    </script>
    </head>
    <body>
    <input type=button onclick="document.all.theDiv.style.display=''" value="Display">
    <div style="border:1px solid pink; width:200px" id="theDiv" onmouseout="div_out()">
    <a href="#">safdf</a>
    <input type=text>
    <button>sss</button>
    </div>
    </body>
    </html>
      

  4.   

    唉,还是自己动手丰衣足食呀.function TimeSpan( oText, oDiv)
    {
        // initialize member variables
        this.oText = oText;
        this.oDiv = oDiv;
        //if the mouse has move out the div
        var mouseout = false;    oDiv.onmouseout = TimeSpan.prototype.onDivMouseOut;
        oDiv.onmouseover = TimeSpan.prototype.onDivMouseOver;
        oDiv.onblur = TimeSpan.prototype.onDivBlur;
    }TimeSpan.prototype.onDivMouseOut = function()
    {
        this.mouseout = true;
    }
    TimeSpan.prototype.onDivMouseOver = function()
    {
        this.mouseout = false;
    }
    TimeSpan.prototype.onDivBlur = function()
    {    if(this.mouseout){
    theDiv.style.visibility = "hidden";
        }
    }function create(){
        new TimeSpan(document.getElementById('bbb'), document.getElementById('theDiv'));    
    }