Query--checkbox全选/反选/取消

来源:互联网 发布:甘肃网络电视台 编辑:程序博客网 时间:2024/05/17 08:00
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><script src="js/jquery-1.6.2.min.js"></script><script>$(function(){//全选$("#checkall").click(function(){     $("input[name='checkbox']:checkbox").attr("checked",true);       });    //全不选$("#checkno").click(function(){     $("input[name='checkbox']:checkbox").attr("checked",false);       });//反选$("#checkrev").click(function(){$("input[name='checkbox']:checkbox").each(function(){$(this).attr("checked",!this.checked); //this.checked=!this.cheked;})           });//提交$("#sub").click(function(){$("input[name='checkbox']:checked").each(function(){alert($(this).val())})           });})</script><title>表单验证demo</title></head><form method="post">     购物网站是:     <br/>         <input  type="checkbox" name="checkbox" value="新蛋" />当当网     <input  type="checkbox" name="checkbox"  value="淘宝" />淘宝     <input  type="checkbox" name="checkbox"  value="京东" />京东             <br/>      <input  type="button" id="checkall"  value="全选" />     <input  type="button" id="checkno" value="全不选" />     <input  type="button" id="checkrev" value="反选" />     <input  type="button" id="sub" value="提交" /></form><body></body></html>

0 0
原创粉丝点击