One example of the Option item in Syllacting Select

zhaozj2021-02-16  53

The SELECT control in Form does not support the sorting of options (option, I will sort the value attribute values ​​in Option, and adjust the location after each Option sort, the specific code is as follows (here, it assumes Value in each Option) The same as the text content):

This function uses the sort method of the Array (array) object to achieve SELECT sorting.

Function Sortme (Osel) {var ln = osel.Options.Length; var arr = new array (); // This is a key part

// Put all the value values ​​of all Option in the Select will be saved in the array (var i = 0; i

/ / If you need to sort the text in the Option, you can change to Arr [i] = osel.options [i] .text; arr [i] = osel.options [i] .value;

}

Arr.sort (); // Start sorting

/ / Clear all Option in SELECT

While (ln -) {osel.options [ln] = null;

// Re-add the sorted array to SELECT

For (i = 0; i

The following example demonstrates a SELECT in ascending order