简单实现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); }); });
效果:
相关推荐
EdwardSiCong 2020-11-23
85477104 2020-11-17
hhanbj 2020-11-17
81427005 2020-11-11
seoppt 2020-09-13
honeyth 2020-09-13
WRITEFORSHARE 2020-09-13
84483065 2020-09-11
momode 2020-09-11
85477104 2020-08-15
83510998 2020-08-08
82550495 2020-08-03
tthappyer 2020-08-03
84901334 2020-07-28
tthappyer 2020-07-25
TONIYH 2020-07-22
tztzyzyz 2020-07-20
83510998 2020-07-18
81463166 2020-07-17