简单实现jQuery多选框功能
2019/6/27 21:30:08
本文主要是介绍简单实现jQuery多选框功能,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
Jquery多选框的基本操作:支持全选、反选、取消全选的功能
HTML正文:
<input type="checkbox" id="c1">全选/全不选<br> 兴趣爱好:<br> <input type="checkbox" name="interst" value="basketball">篮球 <input type="checkbox" name="interst" value="football">足球 <input type="checkbox" name="interst" value="bedminton">羽毛球<br> <input type="button" id="b1" value="全选"> <input type="button" id="b2" value="全不选"> <input type="button" id="b3" value="反选"> <input type="button" id="b4" value="显示">
Javascript操作代码:
$("#c1").click(function(){ if(this.checked){ $("input[name='interst']").attr("checked","checked"); }else{ //$("input[name='interst']").attr("checked",""); //等价于 $("input[name='interst']").removeAttr("checked"); } }); $("#b1").click(function(){ $("input[name='interst']").attr("checked","checked"); }); $("#b2").click(function(){ $("input[name='interst']").attr("checked",""); }); $("#b3").click(function(){ $("input[name='interst']").each(function(){ if(this.checked){ this.checked=""; }else{ this.checked="checked"; } }); }); $("#b4").click(function(){ $("input[name='interst']:checked").each(function(){ alert(this.value); }); });
效果:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持找一找教程网。
这篇关于简单实现jQuery多选框功能的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-30React Native常用组件-点击组件
- 2024-05-30uniapp+vue3+uv-ui手机端后台OA管理模板
- 2024-05-29Python网络爬虫的时候json=就是让你少写个json.dumps()
- 2024-05-27React Native常用组件-展示组件
- 2024-05-27React Native常用组件-列表组件
- 2024-05-09vue3开发前端表单缓存自定义指令,移动端h5必备插件
- 2024-05-09React Hooks在class组件中的使用方式
- 2024-03-30[OIDC in Action] 2. 基于OIDC(OpenID Connect)的SSO(纯JS客户端)
- 2024-03-29terraform jsonencode
- 2024-03-13vuex-persist