jQuery实现 全选/反选

来源:互联网 发布:python安装程序下载 编辑:程序博客网 时间:2024/06/01 09:11

<span style="white-space:pre"></span><input type="checkbox" name="ck"/>1<input type="checkbox" name="ck"/>2<input type="checkbox" name="ck"/>3<input type="checkbox" name="ck"/>4<input type="checkbox" name="ck"/>5<input type="checkbox" name="ck"/>6<input type="checkbox" name="ck"/>7<input type="checkbox" name="ck"/>8<input type="checkbox" name="ck"/>9<input type="checkbox" name="ck"/>10<hr/><input type="checkbox" onclick="checkAll(this,'ck');"/>全选





function checkAll(obj,name){if(jQuery(obj).is(':checked')){//全选    jQuery("[name = "+name+"]:checkbox").prop("checked", true);}else{//全不选    jQuery("[name = "+name+"]:checkbox").prop("checked", false);}}


用attr只能选择一次!prop可重复选择且跨浏览器!


在线DEMO:http://runjs.cn/detail/0gshgazd


0 0
原创粉丝点击