javascript控制网页上checkbox的全选和反选
//checks all checkboxes function checkAll(field) { if (!(field.length)) { field.checked = true; } else { for (var i = 0; i < field.length; i++) { field[i].checked = true; } } } //unchecks all checkboxes function uncheckAll(field) { if (!(field.length)) { field.checked = false; } else { for (var i = 0; i < field.length; i++) { field[i].checked = false; } } } <a href="javascript:checkAll(document.FRM.FIELD);">select</a> / <a href="javascript:uncheckAll(document.FRM.FIELD);">deselect</a> all loop through all checkboxes in a form: function checkAll() { for (i=0; i<document.FormName.elements.length; i++) { if (document.FormName.elements[i].type=="checkbox") document.FormName.elements[i].checked=true; } }