sort items in a dropdown list without the first item

后端 未结 6 1106
粉色の甜心
粉色の甜心 2021-01-04 02:59

I have the following code to sort the items in a dropdown list:

function sortDropDownListByText(selectId) {
    $(selectId).html($(selectId + \" option\").so         


        
6条回答
  •  梦毁少年i
    2021-01-04 03:34

    function sortDropDownListByText(selectId) {
        var foption = $('#'+ selectId + ' option:first');
        var soptions = $('#'+ selectId + ' option:not(:first)').sort(function(a, b) {
           return a.text == b.text ? 0 : a.text < b.text ? -1 : 1
        });
        $('#' + selectId).html(soptions).prepend(foption);              
    
    };
    

    is your function.

提交回复
热议问题