jquery checkbox radio 标签 选中的3种方法
2024-10-13 02:46:41
jquery 很灵活,checkbox radio标签选中的方法有很多,在这儿就例举三个常用的方法。
一,测试html
- <div style="margin-top:150px;">
- <input type='checkbox' name='test[]' class='checkbox' value='checkbox1'>checkbox1
- <input type='checkbox' name='test[]' class='checkbox' value='checkbox2'>checkbox2
- <input type='checkbox' name='test[]' class='checkbox' value='checkbox3'>checkbox3
- </div>
- <div style="margin-top:50px;">
- <input type="radio" name="test1" value = "radio1" class='radio' >radio1
- <input type="radio" name="test1" value = "radio2" class='radio' >radio2
- <input type="radio" name="test1" value = "radio3" class='radio' >radio3
- </div>
二,checkbok,radio选中
方法1,
- //这二个方法属于一类
- $('.checkbox:checked');
- $('input[type^=checkbox]:checked');
方法2,
- $('.checkbox').filter(':checked');
方法3
- $('.checkbox').each(function(){
- if($(this).is(":checked")){
- alert($(this).val()+": is checked");
- }else{
- alert($(this).val()+": is not checked");
- }
- })
将上面的.checkbox换成.radio,就可以判断radio标签的选中了
最新文章
- translate和replace的区别
- 纯CSS下拉导航菜单
- 论meta name= viewport content= width=device-width initial-scale=1 minimum-scale=1 maximum-scale=1的作用
- Bad version number in .class file
- [原]零基础学习在Android进行SDL开发系列文章
- php模拟多线程
- python pip和easy_install使用方式(转载)
- 【DFS+堆的二叉树结构】15轻院校赛-J-堆
- ecshop调用文章显示上一篇下一篇
- easyui datagrid pagesize设置无效
- mysql和mysqli的区别
- Entity Framework,TransactionScope 混合使用的问题讨论
- 开启MySQL远程访问权限 允许远程连接
- SpringBoot 项目在静态工具类中注入 RedisTemplate
- 【Codeforces Round 1120】Technocup 2019 Final Round (Div. 1)
- 利用koa打造restful API
- DOM数据解析
- js实现多物体运动框架并兼容各浏览器
- Yii2发送邮箱总结
- weight decay (权值衰减)