Home > Web Front-end > JS Tutorial > body text

JavaScript code to implement checkbox selection_javascript skills

WBOY
Release: 2016-05-16 16:01:44
Original
1295 people have browsed it

Code:

function checkall(checkNames){
  var allBoxs = document.getElementsByName(checkNames);
  for(var i = 0 ;i<allBoxs.length;i++){
    if(allBoxs[i].type == 'checkbox'){
      if(allBoxs[i].checked==false){
        allBoxs[i].checked = true ;
      }else{
        allBoxs[i].checked = false ;
      }
    }
  }
}
Copy after login

How to use①

Copy code The code is as follows:

Note: 'goods' is the name of all checkboxes that need to be selected

How to use②

<a href="" id="checkAll">全选</a>
<script>
document.getElementById('checkAll').onclick = function () {
  checkall('goods')
};
</script>
Copy after login

Note: 'goods' is the name of all checkboxes that need to be selected

The above two methods are all summarized for you in this article. I hope you will like it. If there is a better method, please let me know. This article will continue to be updated.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!