冻结jquery中的表头
Freeze table header in jquery
我正在尝试冻结表头。我正在使用这个插件来实现同样的目的
当我使用这个插件时,我得到了this.table_obj is undefined
。我试图找出问题出在哪里,但没能找到解决办法。当我在纯html文件中尝试这个代码时,它是有效的,但在服务器端不起作用。您可以在此处看到错误
有什么建议我为什么会出现这个错误吗?
我认为javascript代码期望表id获取该表。可能您在调用javascript代码时没有指定表id,或者指定了错误的表id,或表标记中没有表id。
然而,您可能会看到其他一些jquery插件-http://www.farinspace.com/jquery-scrollable-table-plugin/
你的问题与下面的问题有一定关系。所以,你也可以看看
https://stackoverflow.com/questions/983031/jquery-how-to-freeze-table-header-and-allow-scrolling-of-the-rest-of-the-rows
为了实现我的目标(正如问题中所问的那样(,我已经编写了休耕代码-
这是我写的插件。
(function($){
$.fn.scrollbarTable=function(i){
var o={};
if(typeof(i)=='number')o.height=i;
else if(typeof(i)=='object')o=i;
else if(typeof(i)=='undefined')o={height:300}
return this.each(function(){
var $t=$(this);
var w=$t.width();
$t.width(w-
function(width){
var parent,child;
if(width===undefined){
parent=$('<div style="width:50px;height:50px;overflow:auto"><div style="height:50px;"></div></div>').appendTo('body');
child=parent.children();
width=child.innerWidth()-child.height(99).innerWidth();parent.remove();
}
return width;
}());
var cols=[];
var tableCols=[];
$t.find('thead th,thead td').each(function(){cols.push($(this).width());});
$t.find('tr:eq(1) th,thead td').each(function(){tableCols.push($(this).width());});
var $firstRow=$t.clone();
$firstRow.find('tbody').remove();
$t.find('thead').remove();
$t.before($firstRow);
$firstRow.find('thead th,thead td').each(function(i){$(this).attr('width',cols[i]);});
$t.find('tr:first th,tr:first td').each(function(i){$(this).attr('width',tableCols[i]);});
var $wrap=$('<div>');
$wrap.css({width:w,height:o.height,overflow:'auto'});
$t.wrap($wrap);})};}(jQuery));
如何使用:
$(document).ready(function(){
$('table#tabss').scrollbarTable();
}
希望它能帮助到某个地方的人。。
无论如何,感谢大家的支持…:(
相关文章:
- 修复了使用Jquery的列(表头问题)
- 使用jQuery/Javascript将忽略表头的表的内容复制到剪贴板
- jquery自动滚动表行,但固定了表头
- 使用 jQuery onChange 事件过滤的是过滤表头,而不仅仅是表体
- Mottie jQuery Tablesorter 重置表头内的按钮
- 使用 jQUery 的 HTML 表头样式
- 如何将表头附加到在 jQuery 中使用 getJSON() 函数创建的 html 表
- jQuery DataTables 如何在单击表头时禁用排序
- 获取表行列和表头JQuery
- Jquery数据表包含空白表头
- jQuery数据表头部与垂直滚动不对齐
- 使用jquery通过文本查找TH对象(表头),而无需遍历表的所有TH's
- 我想从JSON数据中打印出一个列表,在jquery中以键作为列表头
- jQuery数据表和jScrollPane -表头不滚动
- 问题,而使用jQuery数据表与特殊的表头
- 我如何使我的CSS滚动固定到表头和第一列(我也开放使用JS或JQuery的想法)
- 使用jQuery数据表时,带colspan的HTML表头
- 如何应用粘贴表头的jquery插件
- 使用jquery从表头隐藏图像
- 冻结jquery中的表头