//得到div在body中所在的绝对坐标
function getAbsPoint(e)
{
var x = e.offsetLeft, y = e.offsetTop;
while(e=e.offsetParent)
{
x += e.offsetLeft;
y += e.offsetTop;
}
x = x-document.body.scrollLeft;//得到相对坐标
y = y-document.body.scrollTop;
return {x:x,y:y};
function getAbsPoint(e)
{
var x = e.offsetLeft, y = e.offsetTop;
while(e=e.offsetParent)
{
x += e.offsetLeft;
y += e.offsetTop;
}
x = x-document.body.scrollLeft;//得到相对坐标
y = y-document.body.scrollTop;
return {x:x,y:y};
}
调用: var testid = document.getElementById(id);
var xy = getAbsPoint(testid);
var x = xy.x,y = xy.y;