Home  >  Article  >  Web Front-end  >  CheckBox 如何实现全选?_JavaScript

CheckBox 如何实现全选?_JavaScript

WBOY
WBOYOriginal
2016-05-16 19:29:19931browse

在一个表单中有很多CheckBox,请问如何实现选种一个而让所有的都选中?  
---------------------------------------------------------------  

function  selectAll(checkBoxName){  
           var  elms  =  document.getElementsByName(checkBoxName);  
           if  (elms.length           var  allChecked  =  true;  
           for  (var  i=0;i                       if  (elms[i].type=="checkbox")  
                                   allChecked  &=  elms[i].checked;  
           for  (var  i=0;i                       if  (elms[i].type=="checkbox"){  
                                               elms[i].checked  =  !allChecked;  
                                               if  (elms[i].onclick)  elms[i].onclick();  
                       }  
}  
---------------------------------------------------------------  

  
    
 全选    

<script> <BR>function mm(o) <BR>{ <BR> var a = document.getElementsByName("m"); <BR> for (var i=0; i<a.length; i++){ <BR> a[i].checked = o.checked; <BR> } <br><br>} <BR></script>









全选:
<script> <BR> function sel(a){ <BR> o=document.getElementsByName(a) <BR> for(i=0;i<o.length;i++) <BR> o[i].checked=event.srcElement.checked <BR> } <BR></script> 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn