This page looks plain and unstyled because you're using a non-standard compliant browser. To see it in its best form, please visit upgrade to a browser that supports web standards. It's free and painless.

Fillano's Learning Notes 會員登入 會員註冊

算兩次也很麻煩,乾脆一次解決。

function Point (_x, _y) {
	this.x = _x;
	this.y = _y;
}
function realPosition(_obj) {
	var currPos = new Point(_obj.offsetLeft,_obj.offsetTop);
	var workPos = new Point(0,0);
	if (_obj.offsetParent.tagName.toUpperCase() != "BODY") {
		workPos = realPosition(_obj.offsetParent);
		currPos.x += workPos.x;
		currPos.y += workPos.y;
	}
	return currPos;
}

這樣就可以一次解決,不必做兩次遞迴。

[2007/10/5]
稍微調整一下,讓程式看起來比較美觀。:D