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

WBOY
Release: 2016-05-16 16:08:51
Original
1913 people have browsed it

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;
  }
}
Copy after login

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>
Copy after login

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

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