Heim > Artikel > Web-Frontend > CheckBox 如何实现全选?_JavaScript
在一个表单中有很多CheckBox,请问如何实现选种一个而让所有的都选中?
---------------------------------------------------------------
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();
}
}
---------------------------------------------------------------
全选
<script> <BR>function mm(o) <BR>{ <BR> var a = document.getElementsByName("m"); <BR> for (var i=0; i<a.length; i++){ <BR> a[i].checked = o.checked; <BR> } <br><br>} <BR></script>
全选:
<script> <BR> function sel(a){ <BR> o=document.getElementsByName(a) <BR> for(i=0;i<o.length;i++) <BR> o[i].checked=event.srcElement.checked <BR> } <BR></script>