张映 发表于 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标签的选中了

最新文章

  1. translate和replace的区别
  2. 纯CSS下拉导航菜单
  3. 论meta name= viewport content= width=device-width initial-scale=1 minimum-scale=1 maximum-scale=1的作用
  4. Bad version number in .class file
  5. [原]零基础学习在Android进行SDL开发系列文章
  6. php模拟多线程
  7. python pip和easy_install使用方式(转载)
  8. 【DFS+堆的二叉树结构】15轻院校赛-J-堆
  9. ecshop调用文章显示上一篇下一篇
  10. easyui datagrid pagesize设置无效
  11. mysql和mysqli的区别
  12. Entity Framework,TransactionScope 混合使用的问题讨论
  13. 开启MySQL远程访问权限 允许远程连接
  14. SpringBoot 项目在静态工具类中注入 RedisTemplate
  15. 【Codeforces Round 1120】Technocup 2019 Final Round (Div. 1)
  16. 利用koa打造restful API
  17. DOM数据解析
  18. js实现多物体运动框架并兼容各浏览器
  19. Yii2发送邮箱总结
  20. weight decay (权值衰减)

热门文章

  1. 笔记:Hibernate 框架配置说明
  2. bootbox的使用
  3. thinkphp5 taglib自定义标签教程
  4. mysql limit 接收变量
  5. 【Python】 xml解析与生成 xml
  6. 利用 mount 指令解决 Read-only file system的问题
  7. 数据库 --&gt; sqlite3总结
  8. Algorithm --&gt; 筛法求素数
  9. oracle管理权限和角色
  10. 慢查询日志(mysql)