当前位置: 代码迷 >> Web前端 >> 怎么实现复选框全选
  详细解决方案

怎么实现复选框全选

热度:23   发布时间:2012-11-23 00:03:43.0
如何实现复选框全选
JS代码如下:

<script type="text/javascript">
var checkflag=false;
function checkedbox(checkname){
     if(checkflag==false){
         for(i=0;i<checkname.length;i++){
              checkname[i].checked=true;
           }
      checkflag=true;
     }else if(checkflag==true){
         for(j=0;j<checkname.length;j++){
              checkname[j].checked=false;
            }
      checkflag=false;
     }         
}
<script>     

JSP页面代码如下:
<body>
	<form name="form1" method="post" action="***.action">
		<table width="100%" border="0" cellspacing="0" cellpadding="0"
			class="listtab">
			<tr class="listtitle">
				<td><input type="checkbox" name="checkAll" value="全选"
					onClick="checkedbox(this.form.delGameId)">
				</td>
			</tr>
			<tr>
				<td align="center"><input type="checkbox" name="delGameId"
					value="${ga.gooId}">
				</td>
			</tr>
		</table>
	</form>
</body>
  相关解决方案