码迷,mamicode.com
首页 > Web开发 > 详细

jquery checkbox radio 标签 选中的3种方法

时间:2017-03-31 00:43:32      阅读:261      评论:0      收藏:0      [点我收藏+]

标签:filter   keyword   type   bar   jquery   href   word   log   复制   

 

张映 发表于 2013-07-16

分类目录: js/jquery

标签:, , ,

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种方法

标签:filter   keyword   type   bar   jquery   href   word   log   复制   

原文地址:http://www.cnblogs.com/huangshikun/p/6649127.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!