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

相关文章
相关标签/搜索