Home >Web Front-end >JS Tutorial >Implementation method of selecting all and inverting selection in JavaScript listbox_javascript skills

Implementation method of selecting all and inverting selection in JavaScript listbox_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 16:08:511969browse

The example in this article describes the implementation method of selecting all and inverting the selection of the JavaScript listbox. Share it with everyone for your reference. The specific analysis is as follows:

Selecting all and inverting selections in a list box through JS code is a common operation and is of great practical value.

function listboxSelectDeselect(listID, isSelect) {
  var listbox = document.getElementById(listID);
  for(var count=0; count < listbox.options.length; count++) {
      listbox.options[count].selected = isSelect;
  }
}

The following is a detailed usage example

Click below buttons to select or deselect all options from select box


<script> function listboxSelectDeselect(listID, isSelect) { var listbox = document.getElementById(listID); for(var count=0; count &lt; listbox.options.length; count++) { listbox.options[count].selected = isSelect; } } </script>

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

Statement:
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