冻结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=$('
').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=$('
'); $wrap.css({width:w,height:o.height,overflow:'auto'}); $t.wrap($wrap);})};}(jQuery));

如何使用:

 $(document).ready(function(){ $('table#tabss').scrollbarTable(); } 

希望它会帮助某个人…

感谢大家的支持…… 🙂