全选、反选、全不选

<input type="button" value="全选" onclick="quanx()">&nbsp;&nbsp;&nbsp;
<input type="button" value="全不选" onclick="quanb()">&nbsp;&nbsp;&nbsp;
<input type="button" value="反选" onclick="quanf()">&nbsp;&nbsp;&nbsp;


//全选
function quanx()
    {
        var abj=document.getElementsByName("chk[]");
            for(i=0;i<abj.length;i++){
                if(abj[i].checked==false){
                abj[i].checked=true;
                }
            }
    }
    
//全不选
function quanb(){
    var bbj=document.getElementsByName("chk[]");
            for(i=0;i<bbj.length;i++){
                if(bbj[i].checked==true){
                bbj[i].checked=false;
                }
            }
}

//反选
function quanf(){
    var cbj=document.getElementsByName("chk[]");
            for(i=0;i<cbj.length;i++){
                if(cbj[i].checked==true){
                cbj[i].checked=false;
                }else{
                cbj[i].checked=true
                }
            }
    }


你可能感兴趣的:(function)