改成
if (oDivLabel.contains(event.toElement)) return;

解决方案 »

  1.   

    同意楼上,对于这个
    element.document.body.appendChild(oDivLabel);
    也是不好的。应该直接这样:
    element.appendChild(oDivLabel);
    然后用相对element的定位。
    (这样event.toElement才有可能有oDivLabel的一份)而事件是这样判断的:
    function onmouseout(event)
    {
        if(element.contains(event.toElement))return;
        //..
    }
      

  2.   

    这个是个例子:<table>
    <tr><td>-------------------<br>-------------------<br>-------------------<br>-------------------<br>
    <tr><td>dasfd</td><td style="background-color:gray"><tr><td>daf</td><td>
    <div id=move1 style="position:absolute;width:200px;height:200px;left:44px;top:55px;background-color:#e0e2e0"> <div id=move2 style="position:relative;width:100px;height:100px;left:30px;top:30px;background-color:blue">
    <div id=move3 style="width:50px;height:50px;left:15px;top:15px;background-color:red">
    <br><br>
    <span id=idspan
    MsgHTML="&lt;span style=&quot;color:red&quot;&gt;ttttttttttttttest&lt;/span&gt;"
    style="behavior:url(test.htc);color:mediumblue;background-color:white"
    >
    这里
    </span>

    <button>def</button>
    </div> <br><br><button>abc</button>
    </div>
    <br><br>
    <button>001</button>
    </div>
    </td><td>dasfd</td></tr>
    <tr><td>dsfa</td></tr></table><script>setInterval(UpdateMsgHTML,100);
    function UpdateMsgHTML()
    {
    idspan.MsgHTML=new Date().getTime();
    }</script>
      

  3.   

    <PUBLIC:COMPONENT>
    <PUBLIC:PROPERTY NAME="MsgHTML" GET="_get_MsgHTML" PUT="_put_MsgHTML"/>
    <PUBLIC:ATTACH EVENT="onmouseover" ONEVENT="_onmouseover()" />
    <PUBLIC:ATTACH EVENT="onmouseout" ONEVENT="_onmouseout()" />
    </PUBLIC:COMPONENT>
    <SCRIPT>var thediv=null;
    var MsgH="";function _get_MsgHTML()
    {
    return MsgH;
    }
    function _put_MsgHTML(v)
    {
    MsgH=v;
    if(thediv)
    thediv.innerHTML=MsgH;
    }function _onmouseover()
    {
    if(element.contains(event.fromElement))return;
    if(thediv)return; //assert(thediv==null);
    thediv=window.document.createElement("DIV");
    with(thediv)
    {
    innerHTML=MsgH;
    }
    with(thediv.runtimeStyle)
    {
    position="absolute";
    left=GetClientScrollX(element)+"px";
    top=GetClientScrollY(element)+element.offsetHeight-1+"px";
    width="100px";
    overflowX="visible";
    backgroundColor="infobackground";
    color="infotext";
    border="1px outset gray";
    }
    element.appendChild(thediv);
    }
    function _onmouseout()
    {
    if(element.contains(event.toElement))return;
    if(thediv);else return; thediv.removeNode(true);
    thediv=null;
    }function GetClientScrollX(e)
    {
    var v=0; do
    {
    v+=e.offsetLeft;
    }while(e=e.offsetElement);

    return v;
    }
    function GetClientScrollY(e)
    {
    var v=0; do
    {
    v+=e.offsetTop;
    }while(e=e.offsetElement);

    return v;
    }
    </SCRIPT>