Home > Web Front-end > JS Tutorial > JavaScript method to sort drop-down list values_javascript skills

JavaScript method to sort drop-down list values_javascript skills

WBOY
Release: 2016-05-16 15:50:14
Original
1703 people have browsed it

The example in this article describes how to use JavaScript to sort drop-down list values. Share it with everyone 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];
  }
}

Copy after login

I hope this article will be helpful to everyone’s JavaScript programming design.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template