复制代码代码如下:
<%@ページ言語= "java" contentType = "text/html; charset = utf-8"
PageEncoding = "UTF-8"%>
<!doctype html public " - // w3c // dtd html 4.01 transitional // en" "http://www.w3.org/tr/html4/loose.dtd">
<html>
<head>
<title> </title>
<スクリプト>
/**
* @param otarget
* @param fnhandler处理的回调函数
*/
function eventhandler(otarget、fnhandler){
if(otarget.addeventlistener){
otarget.addeventlistener( "scroll"、fnhandler、false);
} else if(otarget.attachevent){
otarget.attachevent( "onscroll"、fnhandler);
} それ以外 {
otarget ["onscroll"] = fnhandler;
}
};
function oo(divcontentid、divheaderid){
var div = document.getElementById(divcontentid);
var left = div.scrollleft;
var divheader = document.getElementById(divheaderid);
divheader.scrollleft = left;
var diswidth = div.children [0] .style.width.replace( "px"、 "")
-div.style.width.replace( "px"、 "");
if(div.scrollleft> = diswidth){
divheader.style.overflowy = 'scroll';
} それ以外 {
divheader.style.overflowy = 'hidden';
}
}
window.onload = function onstartlock(){
var odiv = document.getElementById( "divcontentid");
eventhandler(odiv、function(){
oo( "divcontentid"、 "divheaderid");
});
};
</script>
</head>
<body>
<div id = "div1all"
style = "position:absolute;左:0px;右:0px; top:0px; bottom:0px">
<div id = "divheaderid"
style = "margin-right:auto; margin-left:auto; overflow:hidden;">
<テーブルCellSpacing = "0"
style = "border-collapse:collapse; font-size:15px"
bordercolor = "#c1dad7" cellpadding = "0" bgcolor = "#f5fffa"
width = "600px">
<tr style = "background:navy; color:white; height:30px">
<th>ヘッダーa </th>
<th>ヘッダーb </th>
<th>ヘッダーc </th>
<th>ヘッダーd </th>
<th>ヘッダーe </th>
<th>ヘッダーf </th>
</tr>
</table>
</div>
<div id = "divcontentid"
style = "position:absolute; left:0px; top:30.5px; botton:0px;右:0px;オーバーフロー:スクロール">
<テーブルCellSpacing = "0"
style = "border-collapse:collapse; font-size:15px"
bordercolor = "#c1dad7" cellpadding = "0" bgcolor = "#f5fffa"
width = "600px">
<tr>
<td> a </td>
<td> b </td>
<td> c </td>
<td> d </td>
<td> e </td>
<td> f </td>
</tr>
<tr>
<td> a </td>
<td> b </td>
<td> c </td>
<td> d </td>
<td> e </td>
<td> f </td>
</tr>
<tr>
<td> a </td>
<td> b </td>
<td> c </td>
<td> d </td>
<td> e </td>
<td> f </td>
</tr>
<tr>
<td> a </td>
<td> b </td>
<td> c </td>
<td> d </td>
<td> e </td>
<td> f </td>
</tr>
<tr>
<td> a </td>
<td> b </td>
<td> c </td>
<td> d </td>
<td> e </td>
<td> f </td>
</tr>
</table>
</div>
</div>
</body>
</html>