jquery做复选框的全选、全部选、反选

2013-04-11clown_ 的分享   加三联MM小编微信好友:sanlian2018

 <!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" />
<title>复选框的全选反选全不选</title>
<style>
body{ margin:200px;}
</style>
<script language="javascript" type="text/javascript" src="../script/jquery-1.4.2.min.js"></script>
<script>
$(function(){
 $("input[value='全选']").click(function(){
   $("input[type=checkbox]").attr("checked",true);
  })
  $("input[value='全不选']").click(function(){
   $("input[type=checkbox]").attr("checked",false);
  })
  $("input[value='反选']").click(function(){
   $("input[type=checkbox]").each(function(){
   $(this).attr("checked",!$(this).attr("checked"));
    })
  })
 })
</script>
</head>
<body>
<div id="div">
<input type="checkbox" />苹果
<input type="checkbox" />香蕉
<input type="checkbox" />菠萝
<input type="checkbox" />草莓
<input type="checkbox" />梨子<br />
<input type="button" value="全选" /><input type="button" value="反选" /><input type="button" value="全不选" />
</div>
</body>
</html>

TA发布的帖子

881

收藏

605