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

 

張映 發表於 2013-07-16html

分類目錄: js/jqueryjquery

標籤:checkbox, jquery, radio, 選中測試

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

 

一,測試htmlspa

  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選中xml

方法1,htm

  1. //這二個方法屬於一類  
  2. $('.checkbox:checked');  
  3. $('input[type^=checkbox]:checked');  

方法2,blog

  1. $('.checkbox').filter(':checked');  

方法3ip

  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標籤的選中了get

相關文章
相關標籤/搜索