复选框的全选,多选,全选,全不选,反选_转

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >   
  2. < HTML >   
  3. < HEAD >   
  4. < TITLE >  复选框的全选,多选,全不选,反选  </ TITLE >   
  5. < META   NAME = "Generator"   CONTENT = "EditPlus" >   
  6. < META   NAME = "Author"   CONTENT = "" >   
  7. < META   NAME = "Keywords"   CONTENT = "" >   
  8. < META   NAME = "Description"   CONTENT = "" >   
  9.   
  10.   
  11. </ HEAD >   
  12.   
  13. < BODY >   
  14. <!--复选框的全选,多选,全不选,反选   -->   
  15. < form   name = hrong >    
  16. < input   type = checkbox   name = All   onclick = "checkAll('mm')" > 全选 < br />    
  17. < input   type = checkbox   name = mm   onclick = "checkItem('All')" > < br />    
  18. < input   type = checkbox   name = mm   onclick = "checkItem('All')" > < br />    
  19. < input   type = checkbox   name = mm   onclick = "checkItem('All')" > < br />    
  20. < input   type = checkbox   name = mm   onclick = "checkItem('All')" > < br />    
  21. < input   type = checkbox   name = mm   onclick = "checkItem('All')" > < br /> < br />    
  22.   
  23.   
  24. < input   type = checkbox   name = All2   onclick = "checkAll('mm2')" > 全选 < br />    
  25. < input   type = checkbox   name = mm2   onclick = "checkItem('All2')" > < br />    
  26. < input   type = checkbox   name = mm2   onclick = "checkItem('All2')" > < br />    
  27. < input   type = checkbox   name = mm2   onclick = "checkItem('All2')" > < br />    
  28. < input   type = checkbox   name = mm2   onclick = "checkItem('All2')" > < br />    
  29. < input   type = checkbox   name = mm2   onclick = "checkItem('All2')" > < br />    
  30.   
  31. </ form >    
  32.   
  33. < SCRIPT   LANGUAGE = "JavaScript" >    
  34. function checkAll(str)   
  35. {   
  36.     var a  =  document .getElementsByName(str);   
  37.     var n  =  a .length;   
  38.     for (var i = 0 ; i < n ; i++)   
  39.     a[i].checked  =  window .event.srcElement.checked;   
  40. }   
  41. function checkItem(str)   
  42. {   
  43.     var e  =  window .event.srcElement;   
  44.     var all  =  eval ("document.all."+ str);   
  45.     if (e.checked)   
  46.     {   
  47.         var a  =  document .getElementsByName(e.name);   
  48.         all.checked  =  true ;   
  49.         for (var i = 0 ; i < a.length ; i++)   
  50.         {   
  51.             if (!a[i].checked)  
  52.             {   
  53.                 all.checked  =  false ; break;  
  54.             }   
  55.         }  
  56.     }   
  57.     else   
  58.         all.checked  =  false ;   
  59. }  
  60. </ SCRIPT >    
  61.   
  62.   
  63. </ BODY >   
  64. </ HTML >  

你可能感兴趣的:(JavaScript,html)