(转)用JQuery实现Fix表头表格
本文转载自:http://www.cnblogs.com/evlon/archive/2009/06/12/1502239.html
我的技术要点:
1、用两个表,其中一个是表头,另一个是表格做表体
2、两个表格使用相同的百分比宽度
3、在IE下,如果列溢出,则采用 ... 来表示溢出,FF下自动隐藏
4、采用JQuery,把表头的列宽,设置到表体第一列。
5、在窗体大小改变时,自动设置表头的容器宽度为表体的宽度。

不复杂,代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html>
<head>
<title>Untitled</title>
<style type="text/css">
.oddtr
{
background-color:#efefef;
} .fixheader_table table
{
border-collapse:collapse;
width:100%;
border-width:0px;
}
.fixheader_table table td
{
border-collapse:collapse;
width:100%;
border:solid 1px #ccf;
} .fixheader_table > .header
{
}
.fixheader_table > div.body
{
overflow:auto;height:200px; /* IE下这样设置不管用,没有办法,我只好设置到 style中了 */
border:solid 1px red;
} .ellipsis table{
table-layout:fixed;/* 只有定义了表格的布局算法为fixed,下面td的定义才能起作用。 */
}
.ellipsis table tr{
height:25px;
line-height:25px;
} .ellipsis table td{
word-break:keep-all;/* 不换行 */
white-space:nowrap;/* 不换行 */
overflow:hidden;/* 内容超出宽度时隐藏超出部分的内容 */
text-overflow:ellipsis;/* 当对象内文本溢出时显示省略标记() ;需与overflow:hidden;一起使用。*/
}
</style>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(function()
{
var headerCells = $('.fixheader_table .header table tr:first td');
$('.fixheader_table .body table tr:first td').each(function(i,n)
{
$(this).css('width',headerCells.eq(i).css('width'));
});
//关联宽度
$(window).resize(function () {
$('.fixheader_table .header').width($('.fixheader_table > .body table').width());
}).triggerHandler('resize'); });
</script> </head> <body>
<div class="fixheader_table">
<div class="header ellipsis">
<table>
<tr>
<td style="width:40%">标题</td>
<td style="width:30%">姓名</td>
<td style="width:30%">时间</td>
</tr>
</table>
</div>
<div class="ellipsis body" style="overflow:auto;height:200px;">
<table>
<tr>
<td>中国人民大团结万岁</td>
<td>张三</td>
<td>2009-3-6</td>
</tr>
<tr>
<td>中国人民大团结万岁</td>
<td>张三</td>
<td>2009-3-6</td>
</tr>
<tr>
<td>中国人民大团结万岁</td>
<td>张三</td>
<td>2009-3-6</td>
</tr>
<tr>
<td>中国人民大团结万岁</td>
<td>张三</td>
<td>2009-3-6</td>
</tr>
<tr>
<td>中国人民大团结万岁</td>
<td>张三</td>
<td>2009-3-6</td>
</tr>
<tr>
<td>中国人民大团结万岁</td>
<td>张三</td>
<td>2009-3-6</td>
</tr>
<tr>
<td>中国人民大团结万岁</td>
<td>张三</td>
<td>2009-3-6</td>
</tr>
<tr>
<td>中国人民大团结万岁</td>
<td>张三</td>
<td>2009-3-6</td>
</tr>
<tr>
<td>中国人民大团结万岁</td>
<td>张三</td>
<td>2009-3-6</td>
</tr>
<tr>
<td>中国人民大团结万岁</td>
<td>张三</td>
<td>2009-3-6</td>
</tr>
<tr>
<td>中国人民大团结万岁</td>
<td>张三</td>
<td>2009-3-6</td>
</tr>
<tr>
<td>中国人民大团结万岁</td>
<td>张三</td>
<td>2009-3-6</td>
</tr>
<tr>
<td>中国人民大团结万岁</td>
<td>张三</td>
<td>2009-3-6</td>
</tr>
<tr>
<td>中国人民大团结万岁</td>
<td>张三</td>
<td>2009-3-6</td>
</tr>
<tr>
<td>中国人民大团结万岁</td>
<td>张三</td>
<td>2009-3-6</td>
</tr>
<tr>
<td>中国人民大团结万岁</td>
<td>张三</td>
<td>2009-3-6</td>
</tr>
<tr>
<td>中国人民大团结万岁</td>
<td>张三</td>
<td>2009-3-6</td>
</tr>
</table>
</div> </div> </body>
</html>
(转)用JQuery实现Fix表头表格的更多相关文章
- 转:jQuery LigerUI 使用教程表格篇(3) 复选框、多表头、分组、汇总和明细
阅读目录 复选框 多表头 分组 汇总 明细 复选框 grid可以设置复选框模式进行多选,只需要简单的配置 checked:true 获取选中行 如果要获取选中的行,可以用getSelecteds方法: ...
- jQuery——能够编辑的表格
版权声明:欢迎转载,请注明出处 https://blog.csdn.net/suneqing/article/details/26856635 今天学习了利用jQuery实现能够编辑的表格这个 ...
- FineUI小技巧(7)多表头表格导出
前言 之前我们曾写过一篇文章 FineUI小技巧(3)表格导出与文件下载,对于在 FineUI 中导出表格数据进行了详细描述.今天我们要更进一步,介绍下如何导出多表头表格. 多表头表格的标签定义 在 ...
- jQuery(6)——jQuery对表单、表格的操作及更多应用
jQuery对表单.表格的操作及更多应用 [表单应用] 一个表单有表单标签.表单域及表单按钮三个基本部分. 单行文本框应用:获取和失去焦点改变样式. 也可以用CSS中的伪类选择符来实现,但是IE6并不 ...
- HTML多表头表格
1.多表头表格代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://w ...
- JS实现点击表头表格自动排序(含数字、字符串、日期)
这篇文章主要介绍了利用JS如何实现点击表头后表格自动排序,其中包含数字排序.字符串排序以及日期格式的排序,文中给出了完整的示例代码,并做了注释,相信大家都能看懂,感兴趣的朋友们一起来看看吧. < ...
- jQuery 对表单、表格的操作及更多应用-简略笔记
[jQuery 对表单.表格的操作及更多应用] jquery对表单及表格的操作是实际应用中相当广泛. 对于表单的操作,可以实现 (1)获取和失去焦点改变样式: (2)在多行文本框中可以实现网站评论框的 ...
- [转]jQuery实现清空table表格除首行外的所有数据
1.其实网上有很多版本,试了好几个都不行,最后还是查到了一个非常方便的:不会清除表格第一行表头部分. 其中J_tab_fam是table的id. 1 $("#J_tab_fam tr:no ...
- 第5章 jQuery对表单、表格的操作及更多应用
本章主要是对前面4章的小结和应用. 一. 表单form应用 表单分为3个组成部分 (1)form标签 表单可包含文本域,复选框,单选按钮等等.表单用于向指定的 URL 传递用户数据. (2)表单域 - ...
随机推荐
- ListView优化相关
链接1 http://www.jb51.net/article/35273.htm 链接2 http://www.cnblogs.com/xilinch/archive/2012/11/08/2760 ...
- [USACO11JAN]利润Profits
题目描述 The cows have opened a new business, and Farmer John wants to see how well they are doing. The ...
- Codeforces378 D Kostya the Sculptor(贪心)(逻辑)
Kostya the Sculptor time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- POJ1419 Graph Coloring(最大独立集)(最大团)
Graph Coloring Time Limit: 1000MS Memor ...
- bzoj 1061 志愿者招募(最小费用最大流)
[Noi2008]志愿者招募 Time Limit: 20 Sec Memory Limit: 162 MBSubmit: 3792 Solved: 2314[Submit][Status][Di ...
- Python字符串分割
代码如下: [root@localhost test]# cat 3.py #coding=utf-8 ev = """ 1evilxr 2www 3nihao 4evi ...
- TinyXML2读取和创建XML文件 分类: C/C++ 2015-03-14 13:29 94人阅读 评论(0) 收藏
TinyXML2是simple.small.efficient C++ XML文件解析库!方便易于使用,是对TinyXML的升级改写!源码见本人上传到CSDN的TinyXML2.rar资源:http: ...
- spring beans源码解读之 ioc容器之始祖--DefaultListableBeanFactory
spring Ioc容器的实现,从根源上是beanfactory,但真正可以作为一个可以独立使用的ioc容器还是DefaultListableBeanFactory,因此可以这么说, DefaultL ...
- unity3d中切换武器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...
- Unable to determine the principal end of an association between the types '***. The principal end of this association must be explicitly configured using either the relationship fluent API or data annotations.
MVC中数据库表如果是一对一的主键关系时要加[Required]不然会出错Unable to determine the principal end of an association between ...