<!
DOCTYPE
HTML PUBLIC
"-//W3C//DTD HTML 4.01//EN">
< html>
< head>
< title>CheckBox框实现全选功能</ title>
< meta http-equiv= "keywords" content= "keyword1,keyword2,keyword3">
< meta http-equiv= "description" content= "this is my page">
< meta http-equiv= "content-type" content= "text/html; charset=GB18030">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
< script type= "text/javascript">
function selectAll(field) {
//通过checkbox的名称,查询得到所有checkbox框对象
var check = document.getElementsByName( "check");
for( var i= 0; i<check.length; i++) {
//判断全选框的选中状态
if(field. checked) {
check[ i]. checked = true;
} else {
check[ i]. checked = false;
}
}
}
</ script>
</ head>
< body>
< form action= "###">
< input type= "checkbox" name= "checkAll" onclick= "selectAll(this)">--全选< br>
< input type= "checkbox" name= "check">--单选框 1< br>
< input type= "checkbox" name= "check">--单选框 2< br>
< input type= "checkbox" name= "check">--单选框 3< br>
< input type= "checkbox" name= "check">--单选框 4< br>
</ form>
</ body>
</ html>
< html>
< head>
< title>CheckBox框实现全选功能</ title>
< meta http-equiv= "keywords" content= "keyword1,keyword2,keyword3">
< meta http-equiv= "description" content= "this is my page">
< meta http-equiv= "content-type" content= "text/html; charset=GB18030">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
< script type= "text/javascript">
function selectAll(field) {
//通过checkbox的名称,查询得到所有checkbox框对象
var check = document.getElementsByName( "check");
for( var i= 0; i<check.length; i++) {
//判断全选框的选中状态
if(field. checked) {
check[ i]. checked = true;
} else {
check[ i]. checked = false;
}
}
}
</ script>
</ head>
< body>
< form action= "###">
< input type= "checkbox" name= "checkAll" onclick= "selectAll(this)">--全选< br>
< input type= "checkbox" name= "check">--单选框 1< br>
< input type= "checkbox" name= "check">--单选框 2< br>
< input type= "checkbox" name= "check">--单选框 3< br>
< input type= "checkbox" name= "check">--单选框 4< br>
</ form>
</ body>
</ html>