开发者

How to deselect all checkboxes through JavaScript?

开发者 https://www.devze.com 2023-02-12 15:09 出处:网络
How can I deselect all checkboxes usin开发者_运维问答g JavaScript?You can do something like this:

How can I deselect all checkboxes usin开发者_运维问答g JavaScript?


You can do something like this:

function uncheckAll(){
  var frm  = document.getElementById('your form id');

  for (var i = 0; i < count(frm.elements.length); i++){
    if (frm.elements[i].type === 'checkbox'){
      frm.elements[i].checked = false;
    }
  }
}

And to check them all back:

function checkAll(){
  var frm  = document.getElementById('your form id');

  for (var i = 0; i < count(frm.elements.length); i++){
    if (frm.elements[i].type === 'checkbox'){
      frm.elements[i].checked = true;
    }
  }
}

You just have to call those functions.

0

精彩评论

暂无评论...
验证码 换一张
取 消