以下是这个教程的答案
https://www.liaoxuefeng.com/wiki/001434446689867b27157e896e74d51a89c25cc8b43bdb3000/001437110841551950380fdc17c4abdaebd38363dbe2348000
var langList = ['Pascal', 'Lua', 'Ruby']; for(i=0;i<langList.length;i++) { if($("div ul").html().indexOf(langList[i]) != -1) { console.log(langList[i]+" exist!"); continue; } newnode = document.createElement('li'); newnode.innerHTML = "<span>"+langList[i]+"<span>" $("div ul").append(newnode) } var lilist = $("div#test-div>ul>li>span"); s = lilist.map(function(x){return $(this).text();}).sort(); for(let i=0;i<lilist.length;i++) { lilist[i].innerText = (s[i]); }