Discuss / JavaScript / 我的答案

我的答案

Topic source

大梦shake

#1 Created at ... [Delete] [Delete and Lock User]
var ul = $('#test-div>ul');
langs = ['Pascal', 'Lua', 'Ruby'];
for (lang of langs) {
  ul.append(`<li><span>${lang}</span></li>`);
};

var li = ul.children('li').remove().toArray()

li.sort(function (x, y) {
   console.log(x.innerText)
   return x.innerText > y.innerText ? 1 : -1
});
ul.append(li)

  • 1

Reply