我希望能够使用jquery或javascript按每个ID对此列表进行排序。到目前为止,我已经使用过这个,但它没有用。有人可以帮忙吗?
$(".select-sections li").sort(function(a, b) {
return parseInt(a.id) - parseInt(b.id);
}).each(function() {
var elem = $(this);
elem.remove();
$(elem).appendTo(".select-sections");
});
<ul class="select-sections">
<li id="1508931954" class="cart-select cart-mode-cart">1 </li>
<li id="1508932512" class="cart-select cart-mode-cart">13 </li>
<li id="1508932519" class="cart-select cart-current cart-mode-cart">14 </li>
<li id="1508931962" class="cart-select cart-mode-cart">2 </li>
<li id="1508931989" class="cart-select cart-mode-cart">3 </li>
<li id="1508932219" class="cart-select cart-mode-cart">Bay 10 </li>
<li id="1508932254" class="cart-select cart-mode-cart">Bay 11 </li>
<li id="1508932257" class="cart-select cart-mode-cart">Bay 12 </li>
<li id="1508932176" class="cart-select cart-mode-cart"><Bay 4 </li>
<li id="1508932181" class="cart-select cart-mode-cart">Bay 5 </li>
<li id="1508932186" class="cart-select cart-mode-cart">Bay 6 </li>
<li id="1508932191" class="cart-select cart-mode-cart">Bay 7 </li>
<li id="1508932209" class="cart-select cart-mode-cart">Bay 8 </li>
<li id="1508932214" class="cart-select cart-mode-cart">Bay 9 </li>
</ul>