javascript实现全选,反选及全不选

javascript实现全选,反选及全部选

  html 代码:

  

<!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=gb2312" />
<title>无标题文档</title>
<script language="javascript">
  
    function select1(oper){
	  var arr= document.getElementsByName("fav");
	  
	   for(var i=0;i<arr.length;i++){
	      switch(oper){
		  case 1:
		   arr[i].checked=oper;
			    break;
		   case 0:
		  arr[i].checked=oper;
			     break;
		   case -1:
		 arr[i].checked=! arr[i].checked;
			       break;
		  
		  
		  }
	   
	   
	   }
	
	
	}



</script>


</head>

<body>


      <input type="checkbox" name="fav"  value="吃饭"/>吃放
    <input type="checkbox" name="fav"  value="吃饭2"/>吃放2
      <input type="checkbox" name="fav"  value="吃饭3"/>吃放3
      <input type="checkbox" name="fav"  value="吃饭4"/>吃放5
      <input type="checkbox" name="fav"  value="吃饭6"/>吃放6
      <input type="checkbox" name="fav"  value="吃饭7"/>吃放7
      <input type="checkbox" name="fav"  value="吃饭8"/>吃放8
		 
		 
     <input type="button" value="全选"  onclick="select1(1)" />
     <input type="button" value="反选"  onclick="select1(-1)" />
     <input type="button" value="取消"  onclick="select1(0)" />
   
</body>
</html>

 

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