<div class="codetitle"> <span><a style="CURSOR: pointer" data="40018" class="copybut" id="copybut40018" onclick="doCopy('code40018')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code40018"> <br> <br> <br> <br> <br><title>无标题页</title> <br><script src="js/jquery-1.6.min.js" type="text/javascript"></script> <br><script type="text/javascript"> <BR>jQuery(function($){ <BR>//全选 <BR>$("#btn1").click(function(){ <BR>$("input[name='checkbox']").attr("checked","true"); <BR>}) <BR>//取消全选 <BR>$("#btn2").click(function(){ <BR>$("input[name='checkbox']").removeAttr("checked"); <BR>}) <BR>//选中所有基数 <BR>$("#btn3").click(function(){ <BR>$("input[name='checkbox']:even").attr("checked","true"); <BR>}) <BR>//选中所有偶数 <BR>$("#btn6").click(function(){ <BR>$("input[name='checkbox']:odd").attr("checked","true"); <BR>}) <BR>//反选 <BR>$("#btn4").click(function(){ <BR>$("input[name='checkbox']").each(function(){ <BR>if($(this).attr("checked")) <BR>{ <BR>$(this).removeAttr("checked"); <BR>} <BR>else <BR>{ <BR>$(this).attr("checked","true"); <BR>} <BR>}) <BR>}) <BR>//或许选择项的值 <BR>var aa=""; <BR>$("#btn5").click(function(){ <BR>$("input[name='checkbox']:checkbox:checked").each(function(){ <BR>aa+=$(this).val() <BR>}) <BR>document.write(aa); <BR>}) <BR>}) <BR></script> <br> <br> <br><form id="form1" runat="server"> <br><div> <br><input type="button" id="btn1" value="全选"> <br><input type="button" id="btn2" value="取消全选"> <br><input type="button" id="btn3" value="选中所有奇数"> <br><input type="button" id="btn6" value="选中所有偶数"> <br><input type="button" id="btn4" value="反选"> <br><input type="button" id="btn5" value="获得选中的所有值"> <br><br> <br><input type="checkbox" name="checkbox" value="checkbox1"> <br>checkbox1 <br><input type="checkbox" name="checkbox" value="checkbox2"> <br>checkbox2 <br><input type="checkbox" name="checkbox" value="checkbox3"> <br>checkbox3 <br><input type="checkbox" name="checkbox" value="checkbox4"> <br>checkbox4 <br><input type="checkbox" name="checkbox" value="checkbox5"> <br>checkbox5 <br><input type="checkbox" name="checkbox" value="checkbox6"> <br>checkbox6 <br><input type="checkbox" name="checkbox" value="checkbox7"> <br>checkbox7 <br><input type="checkbox" name="checkbox" value="checkbox8"> <br>checkbox8 <br> </div> <br> </form> <br> <br> <br> </div> <br>jquery 循环读取checkbox值 <br><div class="codetitle"> <span><a style="CURSOR: pointer" data="31732" class="copybut" id="copybut31732" onclick="doCopy('code31732')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code31732"> <br>$("input[type=checkbox][checked]").each(function(){ //由于复选框一般选中的是多个,所以可以循环输出 <br>alert($(this).val()); <br>}); <br> </div>