<div class="codetitle"> <span><a style="CURSOR: pointer" data="41192" class="copybut" id="copybut41192" onclick="doCopy('code41192')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code41192"> <br> <br> <br> <br> <title> New document.nbsp;</title> <br> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <br> <script language="javascript" src="http://www.cnjquery.com/demo/jquery.js"></script> <br> <script language="javascript"> <BR> <!-- <BR> $("document.quot;).ready(function(){ <br><br> $("#btn1").click(function(){ <br><br> $("[name='checkbox']").attr("checked",'true');//全选 <br><br> }) <BR> $("#btn2").click(function(){ <br><br> $("[name='checkbox']").removeAttr("checked");//取消全选 <br><br> }) <BR> $("#btn3").click(function(){ <br><br> $("[name='checkbox']:even").attr("checked",'true');//选中所有奇数 <br><br> }) <BR> $("#btn4").click(function(){ <br><br> $("[name='checkbox']").each(function(){ <br><br> <BR> if($(this).attr("checked")) <BR> { <BR> $(this).removeAttr("checked"); <br><br> } <BR> else <BR> { <BR> $(this).attr("checked",'true'); <br><br> } <br><br> }) <br><br> }) <BR> $("#btn5").click(function(){ <BR> var str=""; <BR> $("[name='checkbox'][checked]").each(function(){ <BR> str+=$(this).val()+""r"n"; <BR> //alert($(this).val()); <BR> }) <BR> alert(str); <BR> }) <BR> }) <BR> //--> <BR> </script> <br><br> <br><br> <br> <form name="form1" method="post" action=""> <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="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> </form> <br> </div>