您可以编写一个函数来按两个标准进行排序。
// ORDER BY EmValue, LiMinusEmText
function sortBoth(a, b) {
var aText = $(a).text().replace(/\(\d+\)\s*$/, ""); // chop off the bracket
var bText = $(b).text().replace(/\(\d+\)\s*$/, ""); // and numbers portion
var aValue = +$(a).find("em").text().replace(/\D/g, ""); // parse out em value
var bValue = +$(b).find("em").text().replace(/\D/g, ""); // and convert to number
if (aValue == bValue) {
if (aText == bText) {
return 0;
}
else if (aText < bText) {
return -1;
}
else /*if (aText > bText)*/ {
return 1;
}
}
else {
return aValue - bValue;
}
}
// ORDER BY LiMinusEmText, EmValue
function sortBoth(a, b) {
var aText = $(a).text().replace(/\(\d+\)\s*$/, ""); // chop off the bracket
var bText = $(b).text().replace(/\(\d+\)\s*$/, ""); // and numbers portion
var aValue = +$(a).find("em").text().replace(/\D/g, ""); // parse out em value
var bValue = +$(b).find("em").text().replace(/\D/g, ""); // and convert to number
if (aText == bText) { // strings value same?
return aValue - bValue; // then return a - b
}
else if (aText < bText) {
return -1;
}
else /*if (aText > bText)*/ {
return 1;
}
}