This article mainly introduces how to sort the values of the drop-down list using JavaScript. The example shows how to use javascript to traverse and sort the elements of the drop-down list, for more information about how to sort the values of the drop-down list by using JavaScript, see the following example. Share it with you for your reference. The details are as follows:
Function sortList (id) {var obj = document. getElementById ("id"); var values = new Array (); for (var I = 0; I <obj. options. length; I ++) {values. push (obj. options [I]. innerHTML + "-- xx --" + obj. options [I]. value);} values = values. sort (); for (var I = 0; I <values. length; I ++) {valueArray = values [I]. split ('-- xx --'); obj. options [I]. innerHTML = valueArray [0]; obj. options [I]. value = valueArray [1] ;}}
I hope this article will help you design javascript programs.