Jquery按字母顺序排序列表

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Jquery按字母顺序排序列表相关的知识,希望对你有一定的参考价值。

  1. var mylist = $('ul');
  2. var listitems = mylist.children('li').get();
  3. listitems.sort(function(a, b) {
  4. var compA = $(a).text().toUpperCase();
  5. var compB = $(b).text().toUpperCase();
  6. return (compA < compB) ? -1 : (compA > compB) ? 1 : 0;
  7. })
  8. $.each(listitems, function(idx, itm) { mylist.append(itm); });

以上是关于Jquery按字母顺序排序列表的主要内容,如果未能解决你的问题,请参考以下文章