现在明白了为什么总等于24:
offsetTop:Returns the calculated top position of the element in the element's parent coordinates.
可是,怎样才能得到对象对Body的top position呢?
offsetTop:Returns the calculated top position of the element in the element's parent coordinates.
可是,怎样才能得到对象对Body的top position呢?
但感觉HTML应该提供了这样的属性。
----继续等待高手指点迷津。function changeDivHeight()
{
var theTopToBody=the10Div.offsetTop;
var theParentElement=the10Div.parentElement;
while(theParentElement.tagName!="BODY")
{
theTopToBody=theTopToBody+theParentElement.offsetTop;
theParentElement=theParentElement.parentElement;
}
alert(theTopToBody);
var newHeight=document.body.clientHeight-theTopToBody-20;
the10Div.style.height=newHeight;
the11Div.style.height=newHeight;
}
JK以上的做法仍然错误。
offsetTop:Returns the calculated top position of the element in the element's parent coordinatesJK的做法是基本于将coordinate理解成object
但事实证明这不是对的(尽管在本例里正确,可以刚才在另一实例里遭遇异常。
----盼望高手指点迷津!
{
var top = getObjectOffsetTop(the10Div);
alert(top);
var newHeight=document.body.clientHeight - top -50;
the10Div.style.height=newHeight;
the11Div.style.height=newHeight;
}
function getObjectOffsetTop(obj)
{
var top = obj.offsetTop;
var left= obj.offsetLeft;
while(obj = obj.offsetParent)
{
top += obj.offsetTop; //控件的top
left+= obj.offsetLeft; //控件的left
}
//我这里只输出了 top , left 你自己可酌情输出
return top;
}