function $(Id){return document.getElementById(Id)};
function position(elm){
        var a = elm.offsetHeight;
        var b = elm.offsetWidth;
        var c = elm.offsetLeft;
        var d = elm.offsetTop;
        while(elm=elm.offsetParent){
                c += c;
                d += d;
        };
        return [c,d,b,a]
};
alert(position($('ss')));
这样代码不能再少了吧...
变量多是为了后面的代码少啊...

解决方案 »

  1.   

    elm=elm.offsetParentc += c;
    d += d;不过这里代码很有问题...
      

  2.   

    最简了function $(Id){
    return document.getElementById(Id);
    };
    function position(elm){
    var left = elm.offsetLeft, top = elm.offsetTop;
    while (elm = elm.offsetParent) 
    left += elm.offsetLeft, top += elm.offsetTop;
    return [left, top, arguments[0].offsetWidth, arguments[0].offsetHeight];
    };
    alert(position($('ss')));
      

  3.   


    <script>
    function $(Id){return document.getElementById(Id)};
    function position(elm){
            var o=elm
            var l =o.offsetLeft;
            var t  =o.offsetTop;
            while(o=o.offsetParent){
                    l += o.offsetLeft;
                    t += o.offsetTop;
            };
            return [l,t,elm.offsetWidth,elm.offsetHeight]
    };
    alert(position($('ss')));
    </script>