The example of this article describes the implementation of the JavaScript list box listbox selection and the inverse selection method. Share to everyone for your reference. The specific analysis is as follows:
Through the JS code to select and select the list box is often to operate, very 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;
}
}
Here is a detailed usage example
Click below buttons to select or deselect all options from select box <br> <select id= "Lsbox" name= "Lsbox" siz E= "multiple=" "> <option value=" 1 ">India</option> <option value=" 2 ">united States</opti On> <option value= "3" >China</option> <option value= "4" >Italy</option> <option VA Lue= "5" >Germany</option> <option value= "6" >Canada</option> <option value= "7" >France< /option> <option value= "8" >united kingdom</option> </select> <br> <button onclick= "lis Tboxselectdeselect (' Lsbox ', true); >select all</button> <button onclick= "listboxselectdeselect (' Lsbox ', false);" >deselect all</button> <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>
The
wants this article to help you with your JavaScript programming.