我跟在@ koala_dev的代碼this post嘗試鎖定第一列,我的表水平滾動。不幸的是,代碼對我的表沒有影響。我想知道是否有人可以給我一些關於我做錯了什麼的指示,因爲我是編程新手。修復引導表的第一列
這是我的表: http://jsfiddle.net/mademoiselletse/bypbqboe/59/
這是我在JS插入的代碼(行121-133):
$(function() {
var $tableClass = $('.table');
// Make a clone of our table
var $fixedColumn = $tableClass.clone().insertBefore($tableClass).addClass('fixed-column');
// Remove everything except for first column
$fixedColumn.find('th:not(:first-child),td:not(:first-child)').remove();
// Match the height of the rows to that of the original table's
$fixedColumn.find('tr').each(function(i, elem) {
$(this).height($tableClass.find('tr:eq(' + i + ')').height());
});
});
這是CSS屬性(線36-47)我有插入:
.table-responsive > .fixed-column {
position: absolute;
display: inline-block;
width: auto;
border-right: 1px solid #ddd;
}
@media(min-width:768px) {
.table-responsive>.fixed-column {
display: none;
}
}
我從demo code偏離的唯一的事情是,我定義爲$('.table')
$tableClass
而不是$table
,因爲我之前已將var $table
定義爲$('#table')
。您的幫助將非常感謝!
在您的演示有這$ var'$ tableClass = $('。table');'即你試圖讓你的表對象引用類,但是你已經把'table'作爲'table'而不是'classN ame'作爲'表' –
感謝您指出!我通過ID引用表,但我得到這個: http://jsfiddle.net/mademoiselletse/bypbqboe/62/ 你能給我一些提示,爲什麼這是什麼? – Vic
你的代碼很混亂!你爲什麼要克隆'table',爲什麼要除去第一個表中的所有'table data'和'table head'? –