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获取复选框被选中数量及判断选择值的方法详解
- jQuery中实现prop()函数控制多选框(全选,反选)
- jQuery 获取多选框的值及多选框中文的函数
- jquery中表单 多选框的一种巧妙写法
- jQuery实现的多选框多级联动插件
- jQuery对下拉框,单选框,多选框的操作
- jquery对单选框,多选框,文本框等常见操作小结
- Jquery多选框互相内容交换的实例代码
- jquery select多选框的左右移动 具体实现代码
- jQuery多选框选择数量限制方法