<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>获取元素绝对位置</title>
<script type="text/javascript">
window.onload = function () {
alert(rePos(document.getElementById('s')).y);
};var rePos = function () {
return document.documentElement.getBoundingClientRect && function (o) {
var pos = o.getBoundingClientRect(), root = o.ownerDocument || o.document;
return { x : pos.left + root.documentElement.scrollLeft, y : pos.top + root.documentElement.scrollTop };
} || function (o) {
var x = 0, y = 0;
do { x += o.offsetLeft, y += o.offsetTop; } while (o = o.offsetParent);
return { 'x' : x, 'y' : y };
};
}();
</script>
</head><body>
<div style="height:1000px;">&nbsp;</div>
<table>
<tr><td>&nbsp;</td></tr>
<tr><td bgcolor="#000000";><div id="s">&nbsp;</div></td></tr>
</table>
</body>
</html>