开发者

How to deselect all checkboxes through JavaScript?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜