冻结jquery中的表头

Freeze table header in jquery

本文关键字:表头 jquery 冻结      更新时间:2023-09-26

我正在尝试冻结表头。我正在使用这个插件来实现同样的目的
当我使用这个插件时,我得到了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();
}

希望它能帮助到某个地方的人。。

无论如何,感谢大家的支持…:(