x=obj.offsetLeft;
y=obj.offsetTop;
objParent=obj.offsetParent;
while(objParent.tagName.toUpperCase()!= "BODY"){
x+=objParent.offsetLeft;
y+=objParent.offsetTop;
objParent = objParent.offsetParent;
}
这样根据x,y就可以绝对定位
y=obj.offsetTop;
objParent=obj.offsetParent;
while(objParent.tagName.toUpperCase()!= "BODY"){
x+=objParent.offsetLeft;
y+=objParent.offsetTop;
objParent = objParent.offsetParent;
}
这样根据x,y就可以绝对定位
<div id="testLayer"></div>
<script>
alert(getLayer(testLayer));
function getLayer(obj)
x=obj.offsetLeft;
y=obj.offsetTop;
objParent=obj.offsetParent;
while(objParent.tagName.toUpperCase()!= "BODY"){
x+=objParent.offsetLeft;
y+=objParent.offsetTop;
objParent = objParent.offsetParent;
}
return [x,y]
}
</script>
</body>
谢谢,我把你的代码拷贝到dw里为什么不好使啊,我用的是dw4.0