Jquery選擇複選框操作

來源:互聯網
上載者:User

標籤: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選擇複選框操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.