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