我要实现这样的功能
比如获取元素的坐标值 一般包含x和y坐标
这需要写2个方法来获取
现在能不写成一个方法获取 类似c#的属性 通过 属性.xx 来获取值
不知道这样的function该怎么写?
var getPostion= function()
{
this.postion =function(e)
{
//这里怎么写?
}
}
JScript code:
return {
'x': x,
'y': y
}
getPostion().x
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坐标加了自身的宽度和高度得出的!
引用 JScript codereturn {'x': x,'y': y } getPostion().x
我家电脑原来装的是IE7浏览器,但是最近我爸爸动了某个配置,导致IE7环境下不能运行flash和javascript,看sina或者其他新闻网站上都是一块一块空白,登陆twitter也不成功,报:由于不支持javascript,导致不能登陆。 ......