参考一下吧:<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>
<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>
而楼上这段代码测试了一下,没有这个功能。当鼠标往tip上移动时tip就消失了。
while (tt = tt.offsetParent){t += tt.offsetTop; l += tt.offsetLeft;}
我的问题是:当鼠标移到到某个元素上时,会显示出一个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;
}但我不知道用哪些属性来判断鼠标的位置是否在某个范围内。