jquery checkbox radio 標籤 選中的3種方法

來源:互聯網
上載者:User

標籤:filter   keyword   type   bar   jquery   href   word   log   複製   

 

張映 發表於 2013-07-16

分類目錄: js/jquery

標籤:checkbox, jquery, radio, 選中

jquery 很靈活,checkbox radio標籤選中的方法有很多,在這兒就例舉三個常用的方法。

 

一,測試html

查看複製列印?
  1. <div style="margin-top:150px;">  
  2.     <input type=‘checkbox‘ name=‘test[]‘ class=‘checkbox‘ value=‘checkbox1‘>checkbox1  
  3.     <input type=‘checkbox‘ name=‘test[]‘ class=‘checkbox‘ value=‘checkbox2‘>checkbox2  
  4.     <input type=‘checkbox‘ name=‘test[]‘ class=‘checkbox‘ value=‘checkbox3‘>checkbox3  
  5. </div>  
  6. <div style="margin-top:50px;">  
  7.     <input type="radio" name="test1" value = "radio1" class=‘radio‘ >radio1  
  8.     <input type="radio" name="test1" value = "radio2" class=‘radio‘ >radio2  
  9.     <input type="radio" name="test1" value = "radio3" class=‘radio‘ >radio3  
  10. </div>  

二,checkbok,radio選中

方法1,

查看複製列印?
  1. //這二個方法屬於一類  
  2. $(‘.checkbox:checked‘);  
  3. $(‘input[type^=checkbox]:checked‘);  

方法2,

查看複製列印?
  1. $(‘.checkbox‘).filter(‘:checked‘);  

方法3

查看複製列印?
  1. $(‘.checkbox‘).each(function(){  
  2.     if($(this).is(":checked")){  
  3.         alert($(this).val()+": is checked");  
  4.     }else{  
  5.         alert($(this).val()+": is not checked");  
  6.     }  
  7. })  

將上面的.checkbox換成.radio,就可以判斷radio標籤的選中了

jquery checkbox radio 標籤 選中的3種方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.