我要实现这样的功能
比如获取元素的坐标值 一般包含x和y坐标
这需要写2个方法来获取 
现在能不写成一个方法获取 类似c#的属性 通过 属性.xx 来获取值 
不知道这样的function该怎么写?
 var getPostion= function()
{
   this.postion =function(e)
   {
     //这里怎么写?
    }
}

解决方案 »

  1.   

    return {
      'x': x,
      'y': y
    }getPostion().x
      

  2.   

    function getHtmlPos(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;
    }to包含了4个属性,左,右,上,下,其实就是该元素的距左(x坐标),距顶(y坐标),至于右和下就是x,y坐标加了自身的宽度和高度得出的!