2011-07-06 37 views
0

我試圖凍結表頭。我正在使用this插件來實現相同。
當我使用這個插件時,我得到了this.table_obj is undefined。我試圖找出問題所在,但無法獲得解決方案。 當我在純HTML文件中嘗試此代碼時,它可以工作,但不在服務器端。 你可以看到錯誤here ..
任何建議爲什麼我得到這個錯誤?在jquery中凍結表頭

回答

0

我已經寫休耕代碼以實現我的目標(如在問問題) -

這裏是我寫的插件。

(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(); 
} 

希望這將有助於有人的地方..

感謝任何方式對所有您的實物支持... :)

1

我認爲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