html table内容不随标题滚动

<html>
<head>
</head>
<body>
<div>
<div id="demo" style="overflow:auto;height:80px;width:100;position:relative" onscroll="vertical(this)">
<table border="1" style="position:absolute;z-index:2; " bgcolor=#ff00ff width=100% id=t0>
<tr>
<td id="td1">ttt</td>
<td>ttt中国人</td>
<td>ttt</td>
<td>ttt</td>
<td>ttt</td>
</tr>
</table>
<table border="1" cellpadding="1" height="200" bgcolor=#00ff00 width=100% id=t1 style="position:absolute;z-index:0;">
<tr id="tr1">
<td>asf卡拉挖</td>
<td>asfdd</td>
<td>ddasf</td>
<td>ddasf</td>
<td>ddasf</td>
<td>ddasf</td>
</tr>
<tr id="tr1">
<td>asf卡拉挖</td>
<td>asfdd</td>
<td>ddasf</td>
<td>ddasf</td>
<td>ddasf</td>
<td>ddasf</td>
</tr>
<tr id="tr1">
<td>asf卡拉挖</td>
<td>asfdd</td>
<td>ddasf</td>
<td>ddasf</td>
<td>ddasf</td>
<td>ddasf</td>
</tr>
</table>
</div>
</div>

<script>
var t0 = document.getElementById('t0');
function vertical(obj) {
console.log(obj.scrollTop); //该函数未定义
console.log(this.scrollTop);
console.log(obj.scrollLeft);
//console.log(this); //this 是windows对象
t0.style.top = obj.scrollTop;
}


</script>
</body>
</html>

posted @ 2018-11-02 11:59  enych  阅读(1073)  评论(0编辑  收藏  举报