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.
精彩评论