参考一下吧:<html><head><title>层与按钮对齐</title></head><body>
<div align=left><table border=1 width=600 height=50>
<tr align=center>
  <td>
    <input type=button value=ok onmouseover="cc(this)" alt="提示信息一"
     onmouseout="document.all.pop.style.display='none'">
  </td><td>
    <input type=button value=ok onmouseover="cc(this)" alt="提示信息二"
     onmouseout="document.all.pop.style.display='none'">
  </td><td>
    <input type=button value=ok onmouseover="cc(this)" alt="提示信息三"
     onmouseout="document.all.pop.style.display='none'">
  </td></tr>
</table><div><div id=pop style="
  position: absolute;
  width: 120;
  height: 30;
  z-index: 99;
  display: none;
  background-color: #FF0000"
>
图层文字</div><script language=javascript>
function cc(tt)
{
  var hint = tt.getAttribute("alt");
  var e  = document.getElementById("pop");
  var t  = tt.offsetTop;     //TT控件的定位点高
  var h  = tt.clientHeight;  //TT控件本身的高
  var l  = tt.offsetLeft;    //TT控件的定位点宽
  var ttyp  = tt.type;       //TT控件的类型
  while (tt = tt.offsetParent){t += tt.offsetTop; l += tt.offsetLeft;}
  e.style.top  = (ttyp=="image")? t + h : t + h + 6; //层的 Y 坐标
  e.style.left = l + 1;      //层的 X 坐标
  e.style.display = "block"; //层显示
  e.innerHTML = hint; //author: meizz
}
</script>
</body></html>

解决方案 »

  1.   

    谢谢楼上,不过我的问题是,tip显示出来后,鼠标可以在元素和tip上移动。只有超出这2个元素的范围时,才消失。
    而楼上这段代码测试了一下,没有这个功能。当鼠标往tip上移动时tip就消失了。
      

  2.   

    还有这个循环是什么意思?
    while (tt = tt.offsetParent){t += tt.offsetTop; l += tt.offsetLeft;}
      

  3.   

    捕获 onmoseout 事件参考http://community.csdn.net/Expert/TopicView.asp?id=4406701
      

  4.   

    楼上,你的例子很好。但我的问题不是这个。
    我的问题是:当鼠标移到到某个元素上时,会显示出一个tip,通常鼠标移开,tip会消失。但我想如果用户在元素或者tip移动鼠标时,tip还是显示,只有不在这个范围内时,才消失。我捕获了document.onmousemove事件。来判断。function moveToMouseLoc(e)
    {
    if( document.all.toolTipLayer && document.all.toolTipLayer.style ) 
    {
    var toolTipSTYLE = document.all.toolTipLayer.style; //alert( "mouse" );
    var x = event.x + document.body.scrollLeft;
    var y = event.y + document.body.scrollTop;
    }

    return true;
    }但我不知道用哪些属性来判断鼠标的位置是否在某个范围内。
      

  5.   

    可以给showtip()加上时间限制,几秒内能让tip显示,超过之后就自动隐藏tip,tip也加上onmouseover的fuction,这样如果用户不移动鼠标到tip上tip会几秒后消失,如果移动过去,tip还是继续显示.
      

  6.   

    你需要判断的是发生onmousemove事件的元素即你只需在onmousemove事件中判断当前对象是否是“元素”或“tip”