There are two different ways to implement js to select all and unselect a checkbox

  • 2020-03-30 02:58:39
  • OfStack

There are two different ways to use js to select all and unselect a checkbox:

Method one:

1: js implementation of checkbox selection function:
 
function checkAll() 
{ 
var code_Values = document.getElementsByTagName("input"); 
for(i = 0;i < code_Values.length;i++){ 
if(code_Values[i].type == "checkbox") 
{ 
code_Values[i].checked = true; 
} 
} 
} 

2: js to implement the anti-selection function of checkbox:
 
function uncheckAll() 
{ 
var code_Values = document.getElementsByTagName("input"); 
for(i = 0;i < code_Values.length;i++){ 
if(code_Values[i].type == "checkbox") 
{ 
code_Values[i].checked = false; 
} 
} 
} 

Related articles: