天才一秒记住【9月看书】地址:9yks.com
function bigToSmall() {
allArr.sort(function (a, b) { return b.name - a.name });
appendDom()
}
//取出所有li的data-num属性放进数组
getDom()
function getDom() {
$('#catalog ul li').each(function (m) {
domArr[m] = $(this).attr("data-num");
htmlArr[m] = $(this).html();
})
for (var i = 0; i < domArr.length; i++) {
var activeSubjectsObject = {};
for (var j = 0; j < htmlArr.length; j++) {
if (i == j) {
activeSubjectsObject.name = domArr[i];
activeSubjectsObject.value = htmlArr[j];
allArr.push(activeSubjectsObject);
}
}
}
// console.log(allArr.length)
}
//铺数据
function appendDom() {
$("#catalog ul").html("")
for (i = 0; i < allArr.length; i++) {
$('#catalog ul').append(
`<li data-num=${allArr[i].name}>${allArr[i].value}</li>`
);
}
}
</script>
</body>
</html>