现在有多行表格,要做到的是鼠标移动到最后一列单元格时,显示一个DIV,查看详细信息。这是我现在用的JS:    function showMessage()
    {
        $("#show").show();
        document.getElementById("show").style.left=event.clientX-215;
        document.getElementById("show").style.top=event.clientY+document.body.scrollTop;
    }    function hiddenDiv()
    {
        $("#show").hide();
    }
在最后一列每个单元格中:<td style="cursor:hand" onmousemove="showMessage();" onmouseout="hiddenDiv();">详情</td>
  现在基本的效果都是有了,问题是鼠标在单元格中时,DIV时跟随移动的,且鼠标不能移动到DIV中。我想要鼠标可以移动到DIV中,然后移出DIV或单元格再隐藏。

解决方案 »

  1.   

    <td><a id=a1 onmousemove="showMessage();" onmouseout="hiddenDiv();">详情</a></td>document.getElementById("show").style.left=a的位置/*event.clientX-215*/;
    document.getElementById("show").style.top=a的位置/*event.clientY+document.body.scrollTop*/;
      

  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> 
        <title>XXXXXXXXXX </title> 
    </head> 
    <body> 
    <table width="600" border="1" cellspacing="0" cellpadding="0">
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td style="cursor:hand" onmousemove="showMessage(event,this);" onmouseout="hiddenDiv(event);">&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td style="cursor:hand" onmousemove="showMessage(this);" onmouseout="hiddenDiv(event);">&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td style="cursor:hand" onmousemove="showMessage(this);" onmouseout="hiddenDiv(event);">&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td style="cursor:hand" onmousemove="showMessage(this);" onmouseout="hiddenDiv(event);">&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td style="cursor:hand" onmousemove="showMessage(this);" onmouseout="hiddenDiv(event);">&nbsp;</td>
      </tr>
    </table>
    <div id="show" style="height:300px; width:300px; position:absolute; display:none; background-color:#0000FF; "onmouseout="hiddenDiv(event)";>
    <a href="http://www.sina.com">asdasdasdasd</a>
    <a href="http://www.sina.com">asdasdasdasd</a>
    <a href="http://www.sina.com">asdasdasdasd</a>
    <a href="http://www.sina.com">asdasdasdasd</a>
    </div>
    <script> 
    var $ = function(id){return document.getElementById(id)};function contains(p,e){
            if(!p||!e)return false;
            return p.contains?p.contains(e):p.compareDocumentPosition(e)&16;
    }
    function getobjpos(el,left){
     var val = 0;
         while (el !=null) {
     val += el["offset" + (left? "Left": "Top")];
     el = el.offsetParent;
         }
         return val;
    }
       function showMessage(o)
        { $("show").style.display = "block";
            $("show").style.left=getobjpos(o,1)+o.offsetWidth+"px"
            $("show").style.top=getobjpos(o,0)+"px"
        }    function hiddenDiv(e)
        {
        var e = e || event;
    var obj=e.relatedTarget||e.toElement;
    if(contains($("show"),obj))return
    if(obj.id=="show")return;
           $("show").style.display = "none";
        }
    </script> 
    </body> 
    <div> </div> 
    </html>
      

  3.   

    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>test</title>
    <script src="jquery.js"></script>
    <script>
    function showMessage(obj)
        {
            $("#show").show();
            var offset = getOffset(obj);
            document.getElementById("show").style.left=offset[1]+obj.offsetWidth;
            document.getElementById("show").style.top=offset[0]+document.body.scrollTop;
        }
        
        function getOffset(obj){
    var top = 0;   
    var left = 0; 
    while(obj!=null){
    top += obj.offsetTop;
    left += obj.offsetLeft;
    obj = obj.offsetParent;
    }
    return [top,left];     
        }    function hiddenDiv()
        {
            $("#show").hide();
        }
        window.onload = function(){
         $("#show").hover(function(){$("#show").show();},function(){$("#show").hide();});
        }</script>
    </head><body>
    <table border=1 cellpadding=0 cellspacing=0>
    <tr>
    <td>详情</td>
    <td>详情</td>
    <td style="cursor:hand" onmouseover="showMessage(this);" onmouseout="hiddenDiv();">详情</td>
    </tr>
    <tr>
    <td>详情</td>
    <td>详情</td>
    <td style="cursor:hand" onmouseover="showMessage(this);" onmouseout="hiddenDiv();">详情</td>
    </tr>
    <tr>
    <td>详情</td>
    <td>详情</td>
    <td style="cursor:hand" onmouseover="showMessage(this);" onmouseout="hiddenDiv();">详情</td>
    </tr>
    </table>
    <div id=show style="position:absolute;width:100px;height:100px;background-color:red;display:none">111</div>
    </body></html>
      

  4.   


    不行啊,鼠标不能移到DIV上,我要的就是这个网页左边鼠标移到头像上,然后鼠标能移动到DIV上,可以点击DIV的内容。
      

  5.   


    牛人, 不过为什么我鼠标以上DIV,DIV的内容却变成一片空白了.....