JS实现多个复选框全选

<script language="JavaScript">
function selall1()
{
 
var i = 0;
 
if(document.all("turnit1").value=="全选")
 {
  
for(i=0;i<document.addform.elements.length;i++
  {
      
if(document.addform.elements[i].type == "checkbox"&&(document.addform.elements[i].name=="jcss"))
      {
       document.addform.elements[i].checked
=true;
      }
  } 
  document.all(
"turnit1").value="清除";
 }
 
else
 {
  
for(i=0;i<document.addform.elements.length;i++
  {
      
if(document.addform.elements[i].type == "checkbox"&&(document.addform.elements[i].name=="jcss"))
      {
       document.addform.elements[i].checked
=false;
      }
  } 
  document.all(
"turnit1").value="全选";
 }
}
function selall2()
{
 
var i = 0;
 
if(document.all("turnit2").value=="全选")
 {
  
for(i=0;i<document.addform.elements.length;i++
  {
      
if(document.addform.elements[i].type == "checkbox"&&(document.addform.elements[i].name=="sbqk"))
      {
       document.addform.elements[i].checked
=true;
      }
  } 
  document.all(
"turnit2").value="清除";
 }
 
else
 {
  
for(i=0;i<document.addform.elements.length;i++
  {
      
if(document.addform.elements[i].type == "checkbox"&&(document.addform.elements[i].name=="sbqk"))
      {
       document.addform.elements[i].checked
=false;
      }
  } 
  document.all(
"turnit2").value="全选";
 }
}

</SCRIPT>
<TABLE cellSpacing=0 cellPadding=0 width=96% border=0>
                    
<TBODY>
                    
<FORM name=addform onsubmit="return checkform()" action=hezu_add_save.asp
method=post >
<TR> 
                                
<TD width=15% height="26" align=left><font color="#FF9900">·</font>基础设施: 
                                
</TD>
                                
<TD align=left colSpan=3><LABEL> 
                                  
<input
name=jcss type=checkbox id="jcss2" value=水电 style="margin-left:-5px">
                                  水电
</LABEL> <LABEL> 
                                  
<input
name=jcss type=checkbox id="jcss2" value=煤气>
                                  煤气
</LABEL> <LABEL> 
                                  
<input
name=jcss type=checkbox id="jcss2" value=暖气>
                                  暖气
</LABEL> <LABEL> 
                                  
<input
name=jcss type=checkbox id="jcss2" value=厨房>
                                  厨房
</LABEL> <LABEL> 
                                  
<input name=jcss type=checkbox id="jcss2"
value
=有线>
                                  有线
</LABEL> <LABEL> 
                                  
<input name=jcss type=checkbox id="jcss2"
value
=合金窗>
                                  合金窗
</LABEL> <LABEL> 
                                  
<input name=jcss type=checkbox id="jcss2"
value
=防盗门>
                                  防盗门
</LABEL> <INPUT id=turnit1 onclick=javascript:selall1() type=button value=全选 name=turnit1></TD>
                              
</TR>
<TR> 
                                
<TD align=left height="26"><font color="#FF9900">·</font>配套设施: 
                                
</TD>
                                
<TD align=left colSpan=3 height="26" style="line-height:160%;padding-bottom:2px"> 
                                  
<p> 
                                    
<LABEL> 
                                    
<input type=checkbox value=地板
name=sbqk style="margin-left:-5px">
                                    地板
</LABEL>
                                    
<LABEL> 
                                    
<INPUT type=checkbox value=床
name=sbqk>
                                    床铺
</LABEL>
                                    
<LABEL> 
                                    
<INPUT type=checkbox value=家具
name=sbqk>
                                    家具
</LABEL>
                                    
<LABEL> 
                                    
<input type=checkbox value=电话
name=sbqk>
                                    电话
</LABEL>
                                    
<LABEL> 
                                    
<INPUT
type=checkbox value=电视 name=sbqk>
                                    电视
</LABEL>
                                    
<LABEL> 
                                    
<input
type=checkbox value=空调 name=sbqk>
                                    空调
</LABEL>
                                    
<LABEL> 
                                    
<input
type=checkbox value=洗衣机 name=sbqk>
                                    洗衣机
</LABEL>
                                    
<LABEL> 
                                    
<input
type=checkbox value=电冰箱 name=sbqk>
                                    冰箱
</LABEL>
                                    
<LABEL><br>
                                    
<INPUT type=checkbox value=宽带 name=sbqk style="margin-left:-5px">
                                    宽带
</LABEL>
                                    
<LABEL> 
                                    
<INPUT type=checkbox value=电梯 name=sbqk>
                                    电梯
</LABEL>
                                    
<LABEL> 
                                    
<input type=checkbox value=车位 name=sbqk>
                                    车位
</LABEL>
                                    
<LABEL> </LABEL>
                                    
<LABEL> </LABEL>
                                    
<LABEL> 
                                    
<input
type=checkbox value=热水器 name=sbqk>
                                    热水器
</LABEL>
                                    
<INPUT
type=checkbox value=油烟机 name=sbqk>
                                    油烟机 
                                    
<INPUT onclick=javascript:selall2() type=button value=全选 name=turnit2>
                                  
</p></TD>
                              
</TR>
</form>
</table>

 
posted @ 2008-03-28 00:21  Athrun  阅读(6578)  评论(0编辑  收藏  举报