根据标签的属性值进行排序 其中parentClass是父级标签,timestamp是第一个排序属性,timestampSecond是第二个排序属性
function sort(parentClass, timestamp, timestampSecond) {
var arr_a = []
$('.' + parentClass).children().each(function(index, item) {
arr_a[index] = this;
});
for(i = 0; i < arr_a.length; i++) {
for(j = i + 1; j < arr_a.length; j++) {
if($(arr_a[i]).attr(timestamp) > $(arr_a[j]).attr(timestamp)) {
temp = arr_a[i];
arr_a[i] = arr_a[j];
arr_a[j] = temp;
} else if($(arr_a[i]).attr(timestamp) == $(arr_a[j]).attr(timestamp)) {
if($(arr_a[i]).attr(timestampSecond) > $(arr_a[j]).attr(timestampSecond)) {
temp = arr_a[i];
arr_a[i] = arr_a[j];
arr_a[j] = temp;
}
}
}
}
$('.' + parentClass).html(arr_a)
console.log($('.' + parentClass))
}
sort("change", "timestamp", "timestampSecond")