<div class="codetitle"> <span><a style="CURSOR: pointer" data="33197" class="copybut" id="copybut33197" onclick="doCopy('code33197')"><u>Copy code </u></a></span> The code is as follows: </div> <div class="codebody" id="code33197"> <br><!-- <BR>$("document"). ready(function(){ <BR>$("#btn1").click(function(){ <BR>$("[name='checkbox']").attr("checked",'true'); //Select all<BR>}) <BR>$("#btn2").click(function(){ <BR>$("[name='checkbox']").removeAttr("checked");/ /Unselect all<BR>}) <BR>$("#btn3").click(function(){ <BR>$("[name='checkbox']:even").attr("checked", 'true');//Select all odd numbers <BR>}) <BR>$("#btn4").click(function(){ <BR>$("[name='checkbox']").each( function(){//Reverse selection<BR>if($(this).attr("checked")){ <BR>$(this).removeAttr("checked"); <BR>} <BR>else{ <BR>$(this).attr("checked",'true'); <BR>} <BR>}) <BR>}) <BR>$("#btn5").click(function(){/ /Output the selected value <BR>var str=""; <BR>$("[name='checkbox'][checked]").each(function(){ <BR>str =$(this).val () "rn"; <BR>//alert($(this).val()); <BR>}) <BR>alert(str); <BR>}) <BR>}) <BR>- -> <br> </div> <br><br>where <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="11171" class="copybut" id="copybut11171" onclick="doCopy('code11171')"><u>Copy code </u></a></span> The code is as follows: </div> <div class="codebody" id="code11171"> <br>$("[name='checkbox'][checked]").each(function(){ <br>str =$(this).val() "rn"; //alert($(this ).val()); <br>}) <br> </div> <br>This part of the code does not work properly in FireFox. After searching online, I found a method that can be used normally, as shown below: <br> <div class="codetitle"> <span><a style="CURSOR: pointer" data="50692" class="copybut" id="copybut50692" onclick="doCopy('code50692')"><u>Copy code</u></a></span> The code is as follows:</div> <div class="codebody" id="code50692"> <br>$("[name='checkbox']:checked"). each(function(){ <br>str =$(this).val() "rn"; //alert($(this).val()); <br>}) <br> </div> <br>That is: use $("[name='checkbox']:checked") to correctly obtain the collection of selected controls in the radio/checkbox group<br><strong>After running, you need to refresh</strong><br><div class="htmlarea"><textarea id="runcode41483"> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>louis-blog >> jQuery operation on checkbox</title> <div style="border: 1px solid #999; width: 500px; padding: 15px; background: #eee; margin-top: 150px;"> <form name="form1" method="post" action=""> <input type="button" id="btn1" value=""> </form> </div></textarea></div>