当前位置:首页 > Js实现checkbox全选和全不选

Js实现checkbox全选和全不选

点击次数:1646  更新日期:2011-01-05
\n

用javascript实现checkbox全选和全不选的功能,方便操作,如图:


\n


\n

js代码:


\n

<script language=javascript>


\n

//转载请保留出处 http://www.dwww.cn
function unselectall(){
if(document.myform.chkAll.checked){
document.myform.chkAll.checked = document.myform.chkAll.checked&0;
}
}
function CheckAll(form){
for (var i=0;i<form.elements.length;i++){
var e = form.elements[i];
if (e.Name != ‘chkAll’&&e.disabled==false)
e.checked = form.chkAll.checked;
}
}
</script>


\n

在网页中html中的代码:


\n

<form name=”myform” method=”post” id=”myform” action=”" >


\n

<input name=’id’ type=’checkbox’ onclick=’unselectall()’ id=’id’ value=’1′> 设计家园


\n

<input name=’id’ type=’checkbox’ onclick=’unselectall()’ id=’id’ value=’2′> 网页教程


\n

<input name=’id’ type=’checkbox’ onclick=’unselectall()’ id=’id’ value=’3′> 酷站欣赏


\n

<input name=’id’ type=’checkbox’ onclick=’unselectall()’ id=’id’ value=’4′> 网页素材


\n

<input name=’chkAll’ type=’checkbox’ id=’chkAll’ onclick=’CheckAll(this.form)’ value=’checkbox’>
全选


\n

</form>


\n

作者:无情 出处:http://www.dwww.cn

\n