javascript实现复选框的全选/全不选

 

  
  
  
  
  1. /**  
  2.  * 实现复选框的全选/全不选  
  3.  */ 
  4. sysuser.select = function(){  
  5.   for (var i=0;i<box.length;i++ ){        
  6.       box[i].checked=!box[i].checked;         
  7.   }  
  8. }; 

 js得到选中复选框的值

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>js得到选中复选框的值 </title>
</head>
<body>
<form>
<input type="checkbox" id="box" name="1" value="1"/>
<input type="checkbox" id="box" name="2" value="2"/>
<input type="checkbox" id="box" name="3" value="3"/>
<input type="checkbox" id="box" name="4" value="4"/>
<input type="button" value=" 测 试 " onclick="sysuser.select()"/>
<form>
<body>
<html>
 
/**
 * 得到选中复选框的值
 */

sysuser. select = function ( ) {
  var value = "" ;
    for ( var i = 0 ;i <box. length ;i ++ ) {
        if (box [i ]. checked ) {
            value += box [i ]. value + "," ;
        }          
    }
    value = value. substring ( 0 ,value. length - 1 ) ;
    alert (value ) ;
} ;

你可能感兴趣的:(JavaScript,js,职场,复选框,休闲)