以下代码按如下方式对列表进行排序:1. item, 10. item, 100. item... 我要添加或更改什么以按数字顺序排列列表(1,2,3...)?
function sortUnorderedList(ul, sortDescending) {
if(typeof ul == "string")
ul = document.getElementById(ul);
var lis = ul.getElementsByTagName("LI");
var vals = [];
for(var i = 0, l = lis.length; i < l; i++)
vals.push(lis[i].innerHTML);
vals.sort();
if(sortDescending)
vals.reverse();
for(var i = 0, l = lis.length; i < l; i++)
lis[i].innerHTML = vals[i];
}
window.onload = function() {
var desc = false;
document.getElementById("test").onclick = function() {
sortUnorderedList("lister", desc);
sortUnorderedList("bin", desc);
desc = !desc;
return false;
}
}