我重新发布这个问题是因为我第一次发布它时犯了一个错误:我在提问之前没有足够努力。我想向社区道歉,要求它为我做我的工作
我正在尝试按字母顺序对 div 内的无序列表进行排序。不是列表项在无序列表中,而是无序列表本身。
这是 HTML 的样子:
<div class="FindByCategory">
<ul>
<li> B. This is the first list item in the second unordered list</li>
<li> B. This is the second list item in the second unordered list</li>
</ul>
<ul>
<li> A. This is the first list item in the first unordered list</li>
<li> A. This is the second list item in the first unordered list</li>
</ul>
</div>
我希望它看起来像这样:
<div class="FindByCategory">
<ul>
<li> A. This is the first list item in the first unordered list</li>
<li> A. This is the second list item in the first unordered list</li>
</ul>
<ul>
<li> B. This is the first list item in the second unordered list</li>
<li> B. This is the second list item in the second unordered list</li>
</ul>
</div>
这是我到目前为止所做的:
<script>
function sortUnorderedList(div.FindByCategory, sortDescending) {
if(typeof div.FindByCategory == "string")
div = document.getElementById(div.FindByCategory);
var uls = ul.getElementsByTagName("UL");
var vals = [];
for(var i = 0, l = uls.length; i < l; i++)
vals.push(uls[i].innerHTML);
vals.sort();
for(var i = 0, l = uls.length; i < l; i++)
uls[i].innerHTML = vals[i];
}
$(function(){
FindByCategory()
}
</script>