【发布时间】:2016-08-02 06:40:22
【问题描述】:
我使用 charlietfl 对 StackOverflow 中this 问题的回答对我的 HTML 表中从 1 月到 12 月的月份列进行排序。我只是修改了一些东西,所以我可以在我的网站上使用它。我也在使用tablesorter,所以我可以按字母顺序对其他表格列进行排序。问题是它只适用于 Mozilla Firefox。其他浏览器不会对月份列进行排序。有时 包裹表头的 tr 跳出 thead 标记并进入 tbody 标记。这是我的桌子:http://makzel.com/problems/
这可能是什么原因造成的?
这是我的完整 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
【问题讨论】:
标签: javascript jquery html