0
我使用charlietfl的问题在StackOverflow中对this问题进行排序,以对从1月到12月的HTML表格中的月份列进行排序。我只是修改了一些东西,所以我可以在我的网站上使用它。我也使用tablesorter,所以我可以按字母顺序排列其他表列。问题是它只适用于Mozilla Firefox。其他浏览器不会对月份列进行排序。有时 包装表头的tr跳出了标签并进入tbody标签。这里是我的表格:http://makzel.com/problems/只在Mozilla Firefox中工作的jQuery表格排序代码
这可能是什么原因造成的?
这里是我的全部jQuery代码:
(function($) {
'use strict';
var $window = $(window);
$window.ready(function(){
// Enable sorting for tables
$(".tablesort").tablesorter({
headers: {
0: {
sorter: false
}
}
});
// Sort by month
$('.tablesort th').click(function(){
var sorters =['January','February','March','April','May','June','July','August','September','October','November','December']
var $rows = $('tr:gt(0)').sort(function(a, b){
var aSrcIdx =sorters.indexOf($(a).find('td:first').text());
var bSrcIdx = sorters.indexOf($(b).find('td:first').text());
return aSrcIdx > bSrcIdx;
});
$(this).closest('.tablesort').append($rows);
});
// Tablesort header background change on click
$(".tablesort th").click(function(){
$('.tablesort th').not(this).removeClass('sorted');
$(this).toggleClass('sorted');
});
function postOverflow() {
if ($window.width() < 768) {
$('.tablesort').closest('.post').css("overflow","scroll");
} else{
$('.tablesort').closest('.post').css("overflow","none");
}
}
postOverflow();
$window.resize(postOverflow);
}); // Ready
})(jQuery);
下面是它显示tr标签跳出THEAD标签的链接:http://cms5.revize.com/revize/haddonfield/departments/table_sort_test/index.php
你指的是0 TR内:GT(0)代码?我真的不是很流利的Javascript,所以我不知道它是什么。我会尝试将其更改为-1 – Chad
是的,'return aSrcIdx> bSrcIdx;'应该改变。 – Zenny
好的。我应该用什么替换它? – Chad