哪位大侠帮我看一看,为什么点击按钮后alert出来的总是24,并且滚层的高度不理想

JK_10000 2003-04-09 09:57:09
<html>
<head>
<style>
tr {background-color:expression((sectionRowIndex%2)?'e0e0e0':'eeeeee')};
td{font-size:11}
</style>
</head>

<script language=javascript>
function changeColWidth()
{
if(the11Table.rows[0].style.display=="none")return false;
var theThe10TableColsNum=the10Table.rows[0].cells.length;
for(var i=0;i<theThe10TableColsNum-1;i++)
{
the10Table.rows[0].cells[i].width =the10Table.rows[0].cells[i].offsetWidth;
if(the10Table.rows[1]) the10Table.rows[1].cells[i].width =the10Table.rows[0].cells[i].offsetWidth;
}
var theThe11TableColsNum=the11Table.rows[0].cells.length;
for(var i=0;i<theThe11TableColsNum;i++)
{
the11Table.rows[0].cells[i].width=the11Table.rows[0].cells[i].offsetWidth;
if(the11Table.rows[1]) the11Table.rows[1].cells[i].width=the11Table.rows[0].cells[i].offsetWidth;
}
the00Div.innerHTML="<table width='100%' id=the00Table cellspacing='1' border='0' cellpadding='0' class='tdStyleNonEdit'>"
+the10Table.rows[0].outerHTML+"</table>";
the01Div.innerHTML="<table width='100%' id=the01Table cellspacing='1' border='0' cellpadding='0' class='tdStyleNonEdit'>"
+the11Table.rows[0].outerHTML+"</table>";
the11Table.style.width=the11Table.offsetWidth;
the01Div.style.width=the11Div.style.width;
the10Table.rows[0].style.display="none";
the11Table.rows[0].style.display="none";

changeDivHeight();

}

function changeDivHeight()
{
alert(the10Div.offsetTop);
var newHeight=document.body.clientHeight-the10Div.offsetTop-50;
the10Div.style.height=newHeight;
the11Div.style.height=newHeight;
}
</script>

<body onresize=changeDivHeight()>
<br><br>
<input type=button value="Fix the head tr" onclick="changeColWidth()">
<table width='100%' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td valign=top width=80%>
<div style="overflow-x:hidden;overflow-y:hidden;" id=the00Div >
</div>

<div id=the10Div style="height:100;overflow-x:hidden;overflow-y:auto;" onscroll= "the11Div.scrollTop=scrollTop ">
<table id=the10Table width='100%' cellspacing='1' border='0' cellpadding='0' >
<tr height=22 >
<td nowrap bgcolor="#66CCFF" >Thank you!</td>
<td nowrap bgcolor="#66CCFF" >You are welcome!</td>
</tr>
<tr height=22><td>a</td><td> </td></tr>
<tr height=22><td>a</td><td> </td></tr>
<tr height=22><td>a</td><td> </td></tr>
<tr height=22><td>a</td><td> </td></tr>
<tr height=22><td>a</td><td> </td></tr>
<tr height=22><td>a</td><td> </td></tr>
<tr height=22><td>a</td><td> </td></tr>
<tr height=22><td>a</td><td> </td></tr>
<tr height=22><td>a</td><td> </td></tr>

</table>
<br>
</div>
</td>
<td valign=top >
<div id=the01Div style="overFlow-x:hidden;overflow-y:hidden;" onscroll= "the11Div.scrollLeft=scrollLeft ">
</div>

<div id=the11Div style="width:450; height:100;overFlow-x:auto;overflow-y:hidden;" onscroll= "the10Div.scrollTop=scrollTop;the01Div.scrollLeft=scrollLeft;">
<table id=the11Table width='100%' cellspacing='1' border='0' cellpadding='0' >
<tr height=22>
<td nowrap bgcolor="#66CCFF" >How are you? How are you?How are you? How are you?How are you? How are you?How are you? How are you? </td>
<td nowrap bgcolor="#66CCFF" >I am fine</td>
</tr>
<tr height=22><td>a</td><td> </td></tr>
<tr height=22><td>a</td><td> </td></tr>
<tr height=22><td>a</td><td> </td></tr>
<tr height=22><td>a</td><td> </td></tr>
<tr height=22><td>a</td><td> </td></tr>
<tr height=22><td>a</td><td> </td></tr>
<tr height=22><td>a</td><td> </td></tr>
<tr height=22><td>a</td><td> </td></tr>
<tr height=22><td>a</td><td> </td></tr>

</table>
<br>
</div>
</td>
</tr>
</table>
</body>
</html>
...全文
30 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
JK_10000 2003-04-09
  • 打赏
  • 举报
回复
受益匪浅
非常感谢!
meizz 2003-04-09
  • 打赏
  • 举报
回复
function changeDivHeight()
{
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;
}
JK_10000 2003-04-09
  • 打赏
  • 举报
回复

JK以上的做法仍然错误。
offsetTop:Returns the calculated top position of the element in the element's parent coordinates

JK的做法是基本于将coordinate理解成object
但事实证明这不是对的(尽管在本例里正确,可以刚才在另一实例里遭遇异常。


----盼望高手指点迷津!
JK_10000 2003-04-09
  • 打赏
  • 举报
回复
自己写了个,效果基本上是可以的,
但感觉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_10000 2003-04-09
  • 打赏
  • 举报
回复
现在明白了为什么总等于24:
offsetTop:Returns the calculated top position of the element in the element's parent coordinates.


可是,怎样才能得到对象对Body的top position呢?

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧