admin
管理员
管理员
  • UID1
  • 粉丝2
  • 关注2
  • 发帖数339
  • 社区居民
  • 忠实会员
  • 原创写手
阅读:3794回复:0

js复选框全选反选

楼主#
更多 发布于:2013-10-25 13:59
分享到:
效果图如下

图片:c.png


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Review</title>
<style type="text/css">
<!--
*{
 padding:0px;
 margin:0px;
 font-family:Verdana, Arial, Helvetica, sans-serif;
}
body{
 font-size:12px;
 color:#333333;
}
ul{
 list-style:none;
}
img{
 border:0px;
}
a{
 color:#333333;
 text-decoration:none;
}
a:hover{
 color:#FF3300;
 text-decoration:none;
}
#container {
 width:700px;
 margin:0px auto;
}
#register_list {
 width:600px;
 border-bottom:3px solid #6CC;
}
#listbanner b{
 padding-left:40px;
}
.info_list li {
 height:21px;
 line-height:21px;
 border-bottom:1px dashed #CCC;
}
.info_list li input{
 margin-right:8px;
}
li.bg {
 background-color:#f7f7f7;
}
.info_list span{
 width:100px;
 float:right;
 text-align:center;
}
-->
</style>
<script type="text/javascript">
<!--
function selectall(whosform){
 for(var i=0;i<whosform.elements.length;i++){
    var box = whosform.elements[i];
   if (box.name != 'chkall')
    box.checked = whosform.chkall.checked;
 }
}
function switchall(whosform){
 for(var i=0;i<whosform.elements.length;i++){
    var box = whosform.elements[i];
   if (box.name != 'chkall')
    box.checked = !box.checked;
 }
 var chkall = document.getElementById("chkall");
 if (chkall.checked)
 chkall.checked = !chkall.checked;
}
// -->
</script>
</head>
<body>
<div id="container">
  <div id="register_list">
    <form method="post" name="listform" action="">
      <ul class="info_list">
        <li id="listbanner"><span>注册时间</span><span>联系人</span><span>所在地域</span><b>公司名称</b></li>
        <script type="text/javascript">
          <!--
           var a=1;
           for (var i=1;i<=7;i++){
            if ( a%2 == 0){
            document.write("<li><span>[2008-12-10]</span><span>李芮</span><span>江苏苏州</span><input type=\"checkbox\" name=\"list"+i+"\" id=\"checkbox\" /><a href=\"#\">苏州天颂</a></li>");
            }else{
            document.write("<li class=\"bg\"><span>[2008-12-10]</span><span>李芮</span><span>江苏苏州</span><input type='checkbox' name='list"+i+"' id='checkbox' /><a href=\"#\">苏州天颂</a></li>")
            }
            a=a+1;
           }
          //-->
          </script>
        <li id="listopera">
          <input name="chkall" type="checkbox" id="chkall" value="" onclick="selectall(this.form)"/>
          全选
          <input name="swiall" type="button" id="swiall" value="反选" onclick="switchall(this.form)" />
        </li>
      </ul>
    </form>
  </div>
</div>
</body>
</html>

游客

返回顶部