http://community.csdn.net/Expert/topic/5256/5256513.xml?temp=.9489862

解决方案 »

  1.   

    呵呵 这都行! 
    不怕做不到,只怕想不到!
    不要误会!我是说getInfo()这个方法写得好! 
    我怎么就没想到返回一个Object呢,我获取绝对位置都是通过2个方法获取的一个获取x,一个获取y!
      

  2.   

    PS: 是不是应该先判断下o是否存在 if(o && o!=document.body)
      

  3.   

    不好意思走题了
    LZ的问题可以这样解决<div style="width:180px;overflow-x:hidden;">.....</div>
      

  4.   

    晕。楼上的link打不开,提示Error loading stylesheet: Parsing an XSLT stylesheet failed.
      

  5.   

    <font id=s1 style="font-size:0px"> </font>this.valuesfafdafasfafasdfasfd<font id=s2 style="visibility:hidden"> </font>
    <script language=javascript>alert(getInfo(s2).left-getInfo(s1).left);
    function getInfo(o){//取得坐标
    var to=new Object();
    to.left=to.right=to.top=to.bottom=0;
    var twidth=o.offsetWidth;
    var theight=o.offsetHeight;
    while(o!=document.body){
    to.left+=o.offsetLeft;
    to.top+=o.offsetTop;
    o=o.offsetParent;
    }
    to.right=to.left+twidth;
    to.bottom=to.top+theight;
    return to;
    }
    </script>