黒馬プログラマー——Jqueryの全選と逆選

1886 ワード

———Java  、Android  、iOS  、.Net  、      ! ———
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> New Document </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
 </head>
</style>
  <script src="/js/jquery-1.8.3.js" type="text/javascript"></script>
  <script>
   $(function(){
    $("#all").click(function(){
 // alert($(this).prop("checked"));
 if($(this).prop("checked")){
   //  
$("input[type='checkbox']").prop("checked",true);
$(this).next("span").html("   ");
 }else{
 $("input[type='checkbox']").prop("checked",false);
   $(this).next("span").html("  ");
 }
 
});
$("#reset").click(function(){
 //       
 var a=$("input[type='checkbox']:not(#all):checked");
// alert(a.length);
 //       
 var b=$("input[type='checkbox']:not(#all):not(:checked)")
// alert(b.length);
  a.prop("checked",false);
  b.prop("checked",true);
 
});
   
   });
  
  </script>
 <body>
   <input type="checkbox" /><input type="checkbox" /><input type="checkbox" /><input type="checkbox" /> 
 <input type="checkbox" /><input type="checkbox" /></br>
   <input type="checkbox"  id="all"/><span>  </span> <input type="button"value="  " id="reset"/>
 </body>
</html>