CheckBox 如何实现全选?_JavaScript
程序员文章站
2022-04-25 13:40:33
...
在一个表单中有很多CheckBox,请问如何实现选种一个而让所有的都选中?
---------------------------------------------------------------
function selectAll(checkBoxName){
var elms = document.getElementsByName(checkBoxName);
if (elms.length var allChecked = true;
for (var i=0;i if (elms[i].type=="checkbox")
allChecked &= elms[i].checked;
for (var i=0;i if (elms[i].type=="checkbox"){
elms[i].checked = !allChecked;
if (elms[i].onclick) elms[i].onclick();
}
}
---------------------------------------------------------------
全选
全选:
---------------------------------------------------------------
function selectAll(checkBoxName){
var elms = document.getElementsByName(checkBoxName);
if (elms.length var allChecked = true;
for (var i=0;i
allChecked &= elms[i].checked;
for (var i=0;i
elms[i].checked = !allChecked;
if (elms[i].onclick) elms[i].onclick();
}
}
---------------------------------------------------------------
全选
全选:
推荐阅读