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 < listbox.options.length; count++) { listbox.options[count].selected = isSelect; } } </script>
I hope this article will be helpful to everyone’s JavaScript programming design.