<div class="codetitle"> <span><a style="CURSOR: pointer" data="62009" class="copybut" id="copybut62009" onclick="doCopy('code62009')"><u>Copy code</u></a></span> The code is as follows:</div> <div class="codebody" id="code62009"> <br><html> <br><head> <br>< ;title> <br>checkbox test<br></title> <br><script type='text/javascript' src='jquery-1.8.2.min.js'></script> <br><br><script type="text/javascript"> <br>$(document).ready(function(){ <br>$("#all").change(function() { <br>//alert($("#all").val()); //Get the value of checkbox<br>// alert($("#all").get(0).checked); //value For true and false <br>if($("#all").get(0).checked){ //Convert the jquery object into a dom object using the properties of the dom object <br>$(":checkbox" ).attr({ <br>//checked: 'checked' can be replaced with the following sentence <br>"checked":true <br>}); <br>}else{ <br>//$(":checkbox ").removeAttr('checked'); can be replaced with the following sentence <br>$(":checkbox").attr({ <br>"checked":false <br>}); <br>} <br> //The first method of operating arrays<br>/* //each(function()) function<br>var arr=new Array(); //General processing is that the value in the checkbox is represented by an array and passed to the background<br> var i=0; <br>$(":checkbox").each(function(index){ <br>if($(this).val()=="1"){ <br>return true; <br>} <br>arr[i]=$(this).val(); <br>alert(i "preceded by the subscript and followed by the value" arr[i ]); //Get the checkbox value<br>} ); */ <br>//The second method of operating arrays <br>var arr= new Array(); <br>$(":checkbox").each(function(index){ <br>if($ (this).val()!="1"){ <br>arr.push($(this).val()); <br>} <br><br>}); <br>//Group output array values <br>for(var j=0;j<arr.length;j ){ <BR>alert(arr[j]); <BR>} <BR>var str=arr.join(", "); //Use the array to concatenate it into a string <BR>alert(str); //Output the string <BR>}); <br><br>}); <br><br>< /script> <br></head> <br><body> <br><input type='checkbox' id='all' value='1' />Select all<br /> <br><input type='checkbox' id='all1' value='2' />num1<br /> <br><input type='checkbox' id='all2' value='3 ' />num2<br /> <br><input type='checkbox' id='all3' value='4' />num3<br /> <br><input type='checkbox ' id='all5' value='5' />num4<br /> <br></body> <br></html> <br> </div>