この質問を最初に投稿したときに間違えたため、この質問を再投稿しています。質問する前に十分な努力をしていませんでした。そして、私のために私の仕事をするようにコミュニティに依頼してくれたことをコミュニティに謝罪したいと思います
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>