CheckBox 实现全选功能

                            <input name="selectall" type="checkbox" value="checkbox" id="selectall"
                                onclick
="javascript:sall(this.checked);" />全选</td>
<script type="text/ecmascript">
                
function sall(status)
                {
                        
var objs = document.getElementsByTagName("input");
                        
for(var i=0; i<objs.length; i++)
                        {
                            
if(objs[i].type.toLowerCase() == "checkbox" )
                            {
                                  
if(objs[i].name.toLowerCase() == "commentid")            
                                  objs[i].checked 
= status; 
                            }
                                
                        }  
                }
                
function CheckSatus(sallid)
                {
                        document.getElementById(sallid).checked 
= true;
                        
var objs = document.getElementsByTagName("input");
                        
for(var i=0; i<objs.length; i++)
                        {
                            
if(objs[i].type.toLowerCase() == "checkbox" )
                            {
                                    
                                  
if(objs[i].name.toLowerCase() == "commentid")
                                  {
                                      
                                      
if(!objs[i].checked)
                                      {
                                        document.getElementById(sallid).checked 
= false;
                                      }
                                  }
                                  
                            }
                                
                        } 
                }
                        
</script>

<input name="commentid" type="checkbox" value='11' onclick="javascript:CheckSatus('selectall');"/>

<input name="commentid" type="checkbox" value='12' onclick="javascript:CheckSatus('selectall');"/>

<input name="commentid" type="checkbox" value='13' onclick="javascript:CheckSatus('selectall');"/>
原文地址:https://www.cnblogs.com/heimirror/p/1218508.html