
new document script>
function FixTable(TableID, FixColumnNumber, width, height) {
///
/// 锁定表头和列
/// sorex.cnblogs.com
/// ///
/// 要锁定的Table的ID
///
///
/// 要锁定列的个数
///
///
/// 显示的宽度
///
///
/// 显示的高度
///
if ($("#" + TableID + "_tableLayout").length != 0) {
$("#" + TableID + "_tableLayout").before($("#" + TableID));
$("#" + TableID + "_tableLayout").empty();
}
else {
$("#" + TableID).after("");
}
$(
''
+ '').appendTo("#" + TableID + "_tableLayout");
var oldtable = $("#" + TableID);
var tableFixClone = oldtable.clone(true);
tableFixClone.attr("id", TableID + "_tableFixClone");
var tableHeadClone = oldtable.clone(true);
tableHeadClone.attr("id", TableID + "_tableHeadClone");
var tableColumnClone = oldtable.clone(true);
tableColumnClone.attr("id", TableID + "_tableColumnClone");
$("#" + TableID + "_tableColumn").append(tableColumnClone);
$("#" + TableID + "_tableData").append(oldtable);
$("#" + TableID + "_tableLayout table").each(function () {
$(this).css("margin", "0");
});
;
var ColumnsWidth = 0;
var ColumnsNumber = 0;
$("#" + TableID + "_tableColumn tr:last td:lt(" + FixColumnNumber + ")").each(function () {
ColumnsWidth += $(this).outerWidth(true);
ColumnsNumber++;
});
ColumnsWidth += 2;
if ($.browser.msie) {
switch ($.browser.version) {
case "7.0":
if (ColumnsNumber >= 3) ColumnsWidth--;
break;
case "8.0":
if (ColumnsNumber >= 2) ColumnsWidth--;
break;
}
}
$("#" + TableID + "_tableColumn").css("width", ColumnsWidth);
$("#" + TableID + "_tableData").scroll(function () {
$("#" + TableID + "_tableColumn").scrollTop($("#" + TableID + "_tableData").scrollTop());
});
$("#" + TableID + "_tableColumn").css({ "overflow": "hidden", "height": height - 17, "position": "relative", "z-index": "40", "background-color": "Silver" });
$("#" + TableID + "_tableData").css({ "overflow": "scroll", "width": width, "height": height, "position": "relative", "z-index": "35" });
if ($("#" + TableID + "_tableColumn").height() > $("#" + TableID + "_tableColumn table").height()) {
$("#" + TableID + "_tableColumn").css("height", $("#" + TableID + "_tableColumn table").height());
$("#" + TableID + "_tableData").css("height", $("#" + TableID + "_tableColumn table").height() + 17);
}
$("#" + TableID + "_tableColumn").offset($("#" + TableID + "_tableLayout").offset());
$("#" + TableID + "_tableData").offset($("#" + TableID + "_tableLayout").offset());
}
$(document).ready(function () {
FixTable("MyTable", 2, 600, 400);
});
//-->
script>
鸣谢原文转自
http://www.cnblogs.com/sorex/archive/2011/06/30/2093499.html
style="border-bottom-color: black; border-top-color: black; width: 1000px; color: #000000; border-right-color: black; font-size: medium; border-left-color: black"
id="MyTable"
border="1"
cellspacing="0"
cellpadding="0"
>
姓名 |
班级 |
成绩 |
主科 |
文科 |
理科 |
总分 |
语文 |
数学 |
英语 |
政治 |
历史 |
地理 |
物理 |
化学 |
生物 |
姓名 |
班级 |
语文 |
数学 |
英语 |
政治 |
历史 |
地理 |
物理 |
化学 |
生物 |
总分 |
学生32 |
班级1 |
29 |
25 |
146 |
28 |
79 |
73 |
47 |
8 |
91 |
526 |
浏览器大时候:
浏览器小时候:
各位请支个招,分管够。谢谢。
回复讨论(解决方案)
大家有好的方法。发邮箱 245322563@qq.com谢谢