標籤:style blog http color os io java ar for
1 <script type="text/javascript"> 2 jQuery(function($){ 3 //全選 4 $("#btn1").click(function(){ 5 $("input[name=‘checkbox‘]").attr("checked","true"); 6 }) 7 //取消全選 8 $("#btn2").click(function(){ 9 $("input[name=‘checkbox‘]").removeAttr("checked");10 })11 //選中所有基數12 $("#btn3").click(function(){13 $("input[name=‘checkbox‘]:even").attr("checked","true");14 })15 //選中所有偶數16 $("#btn6").click(function(){17 $("input[name=‘checkbox‘]:odd").attr("checked","true");18 })19 //反選20 $("#btn4").click(function(){21 $("input[name=‘checkbox‘]").each(function(){22 if($(this).attr("checked"))23 {24 $(this).removeAttr("checked");25 }26 else27 {28 $(this).attr("checked","true");29 }30 })31 })32 //或許選擇項的值33 var aa="";34 $("#btn5").click(function(){35 $("input[name=‘checkbox‘]:checkbox:checked").each(function(){36 aa+=$(this).val()37 })38 document.write(aa);39 })40 })
1 <form id="form1" runat="server"> 2 <div> 3 <input type="button" id="btn1" value="全選"> 4 <input type="button" id="btn2" value="取消全選"> 5 <input type="button" id="btn3" value="選中所有奇數"> 6 <input type="button" id="btn6" value="選中所有偶數"> 7 <input type="button" id="btn4" value="反選"> 8 <input type="button" id="btn5" value="獲得選中的所有值"> 9 <br>10 <input type="checkbox" name="checkbox" value="checkbox1">11 checkbox112 <input type="checkbox" name="checkbox" value="checkbox2">13 checkbox214 <input type="checkbox" name="checkbox" value="checkbox3">15 checkbox316 <input type="checkbox" name="checkbox" value="checkbox4">17 checkbox418 <input type="checkbox" name="checkbox" value="checkbox5">19 checkbox520 <input type="checkbox" name="checkbox" value="checkbox6">21 checkbox622 <input type="checkbox" name="checkbox" value="checkbox7">23 checkbox724 <input type="checkbox" name="checkbox" value="checkbox8">25 checkbox826 </div>27 </form>
View Code
Jquery選擇複選框操作