Sorting Select box with jQuery

后端 未结 5 1841
情话喂你
情话喂你 2021-01-04 10:20

I have a select box on a form, which carries an incremental rel attribute. I have a function that can sort the options by thier .text() value, into alphabetcal order.

<
5条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-04 11:03

    I needed a similar solution then made ​​some changes to the original function and it worked fine.

    function NASort(a, b) {  
        return (a.innerHTML.toLowerCase() > b.innerHTML.toLowerCase()) ? 1 : -1;
    };
    
    $('select option').sort(NASort).appendTo('select');
    

提交回复
热议问题