javascript 获取控件的绝对位置

调用方法:
var pos=GetObjPos(ID);

function CPos(x, y)
{
    
this.x = x;
    
this.y = y;
}

//获取控件的位置
function GetObjPos(ATarget)
{
    
var target = ATarget;
    
var pos = new CPos(target.offsetLeft, target.offsetTop);
    
    
var target = target.offsetParent;
    
while (target)
    
{
        pos.x 
+= target.offsetLeft;
        pos.y 
+= target.offsetTop;
        
        target 
= target.offsetParent
    }

    
    
return pos;
}
posted on 2008-03-27 13:45  ringwang  阅读(2632)  评论(1编辑  收藏  举报