数据排序,从小到大,从大到小,ajax

var sortThread = {};
$(function () {
sortThread.sortAscending = true;
$(".sort").on("click", function () {
sortThread.sortAscending = !sortThread.sortAscending;

var $msgListItem = $(".message-list-item");

$msgListItem.sort(function (a, b) {
var sort1 = a.getAttribute('data-sort') * 1;
var sort2 = b.getAttribute('data-sort') * 1;

var sortNum = 1;
if (!sortThread.sortAscending)
sortNum = -1;

if (sort1 > sort2)
return 1 * sortNum;
if (sort1 < sort2)
return -1 * sortNum;

return 0;
});

$msgListItem.detach().appendTo("#MessageList");

});
});

数据排序

猜你喜欢

转载自www.cnblogs.com/wjhaaa/p/10607579.html