Chinaunix首页 | 论坛 | 博客
  • 博客访问: 479392
  • 博文数量: 112
  • 博客积分: 5696
  • 博客等级: 大校
  • 技术积分: 1720
  • 用 户 组: 普通用户
  • 注册时间: 2007-08-17 09:58
文章分类

全部博文(112)

文章存档

2011年(22)

2010年(28)

2009年(21)

2008年(41)

分类:

2008-03-10 20:01:59

//使用方法
var tempobj = document.getElementById("控件ID");
var pos = getAbsolutePosition(tempobj);
alert(
""+pos.x+","+pos.y);

//函数
function getAbsolutePosition(obj)
{
position 
= new Object();
position.x 
= 0;
position.y 
= 0;
var tempobj = obj;
while(tempobj!=null && tempobj!=document.body)
{
position.x 
+= tempobj.offsetLeft + tempobj.clientLeft;
position.y 
+= tempobj.offsetTop + tempobj.clientTop;
tempobj 
= tempobj.offsetParent
}

return position;
}

阅读(622) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~