您的位置:首页 > 其它

获取指定元素的位置并提示信息

2010-08-26 18:29 330 查看
<HTML>

<head>

<title>无标题页</title>
<style>
div
{
position:absolute;
z-index:100;
border: 1px solid red;
width:100%;
height:100px
}
</style>

</head>
<body>

<script>

//取得元素左边的位移
function getL(e){
var l=e.offsetLeft;
while(e=e.offsetParent){
l+=e.offsetLeft;
}
return l;
}

//取得元素顶部的位移
function getT(e){
var t=e.offsetTop;
while(e=e.offsetParent){
t+=e.offsetTop;
}
return t;
}

function show(o,obj){
var object=document.getElementById(obj);
if(object ==null)
{
var m=document.createElement("div");
m.id=obj;

//可用ajax处理从后台读取数据显示在此处
var txt=document.createTextNode(o.innerHTML);
m.appendChild(txt);
m.style.pixelLeft=getL(o)+o.offsetWidth;
m.style.pixelTop=getT(o)+o.offsetHeight;
document.body.appendChild(m);
}

</script>

function hide(obj)
{
var object=document.getElementById(obj);
if(object !=null)
{
document.body.removeChild(document.getElementById(obj));
}
}

<table>
<tr>
<td><input id="Text1" type="text" onmouseover="show(this,'m')" onmouseout="hide('m')" /></td>

</tr>


</table>

</body>
</HTML>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: