js代码
<script type="text/javascript">
function selectAll() {
var elements = document.getElementsByTagName('input');
var ch = document.getElementById("allselect_top");
if (ch.checked) {/* 全选 */
for ( var i = 0; i < elements.length; i++) {
if (elements[i].type == 'checkbox') {
if (elements[i].checked == false) {
elements[i].checked = true;
}
}
}
}else{ /* 反选 */
for ( var i = 0; i < elements.length; i++) {
if (elements[i].type == 'checkbox') {
if (elements[i].checked == true) {
elements[i].checked = false;
}
}
}
}
}
</script>
HTML代码
<input type="checkbox" id="allselect_top" class="ipc allselect" οnclick="selectAll()">