JavaScript学习总结
1]获得HTML页面控件上某一控件的右下坐标值:
function getHW(obj)
{
var showLeft=GetLeft(Get$("tbQuery"));
var showTop=GetTop(Get$("tbQuery"));
Get$("ShowDiv").style.top=showTop+Get$("tbQuery").clientHeight;
Get$("ShowDiv").style.left=showLeft;
}
![]()
![]()
function Get$(obj)
{
return document.getElementById(obj);
}
![]()
function GetTop(obj)//获取HTML页面中标签的绝对位置
{
var top=obj.offsetTop;
if(obj.offsetParent.tagName!="BODY")//循环到BODY
{
top+=GetTop(obj.offsetParent);//加上BODY的值
}
else//必须加上,不然在递归过程中会多加一次.
{
top+=obj.offsetParent.offsetTop;
}
return top;
}
![]()
function GetLeft(obj)
{
var top=obj.offsetLeft;
if(obj.offsetParent.tagName!="BODY")
{
top+=GetLeft(obj.offsetParent);
}
else
{
top+=obj.offsetParent.offsetLeft;
}
return top;
}
function getHW(obj)
{
var showLeft=GetLeft(Get$("tbQuery"));
var showTop=GetTop(Get$("tbQuery"));
Get$("ShowDiv").style.top=showTop+Get$("tbQuery").clientHeight;
Get$("ShowDiv").style.left=showLeft;
}

function Get$(obj)
{
return document.getElementById(obj);
}
function GetTop(obj)//获取HTML页面中标签的绝对位置
{
var top=obj.offsetTop;
if(obj.offsetParent.tagName!="BODY")//循环到BODY
{
top+=GetTop(obj.offsetParent);//加上BODY的值
}
else//必须加上,不然在递归过程中会多加一次.
{
top+=obj.offsetParent.offsetTop;
}
return top;
}
function GetLeft(obj)
{
var top=obj.offsetLeft;
if(obj.offsetParent.tagName!="BODY")
{
top+=GetLeft(obj.offsetParent);
}
else
{
top+=obj.offsetParent.offsetLeft;
}
return top;
}作者:Bober Song
出处:http://bober.cnblogs.com/
CARE健康网: http://www.aicareyou.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
出处:http://bober.cnblogs.com/
CARE健康网: http://www.aicareyou.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。




浙公网安备 33010602011771号