checkbox的名字和id必须是一样的吗?

解决方案 »

  1.   

    <html>
    <head>
    <title>添加或修改记录</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <LINK href="../../inc/Style.css" rel=stylesheet type=text/css><script language="javascript">
    function submitit()
    {
    if(isEmpty(form1.file1.value))
    {
    alert("附件不能为空");
    document.form1.file1.focus();
    return false;
    } var aa = 0;
    for(i=0;i<=form1.xzr.length-1;i++){
    if(form1.xzr[i].checked){
    aa = 1;
    break;
    }
    }
    if(aa == 0){
    alert("请选择下载人");
    form1.xzr[0].focus();
    return false;
    }
    }function isEmpty(sStr)
    {
      var oRegExp=/^[ ]*$/
      return oRegExp.test(sStr)
    }
    function fncBtn(btn)
    {
    if (btn=="b1")
    {
    if (document.form1.line1.value=="")
    {
    document.form1.elements[2].checked=true;
    document.form1.elements[3].checked=true;
    document.form1.elements[4].checked=true;
    document.form1.elements[5].checked=true;
    document.form1.line1.value=1;
    }
    else
    {
    document.form1.elements[2].checked=false;
    document.form1.elements[3].checked=false;
    document.form1.elements[4].checked=false;
    document.form1.elements[5].checked=false;
    document.form1.line1.value="";
    }

    }

    if (btn=="b2")
    {
    document.form1.a2.checked=true;
    if (document.form1.line2.value=="")
    {
    document.form1.elements[7].checked=true;
    document.form1.elements[8].checked=true;
    document.form1.line2.value=1;
    }
    else
    {
    document.form1.elements[7].checked=false;
    document.form1.elements[8].checked=false;
    document.form1.line2.value="";
    } }}</script>
    </head><body>
    <p align="center"><STRONG><FONT color=#006633 face=宋体 size=+2> <U> 公 共 存 储</U></FONT></STRONG>&nbsp; 
    </p>
    <form action="ins.asp" method="post" enctype="multipart/form-data" name="form1" onsubmit="javascript:return submitit();">
      <table width="70%" border="0" align="center" cellpadding="0" cellspacing="10">
        <tr> 
          <td>附件:</td>
          <td><input name="file1" type="file" class="CheckBox" size="50"></td>
        </tr>
        <tr> 
          <td>备注:</td>
          <td><textarea name="nr" cols="59" rows="2" class="CheckBox"></textarea></td>
        </tr>
        <tr>
          <td width="15%">下载人:</td>
          <td> 
    <b>第1组:</b>&nbsp;
    <input type="checkbox" name="xzr" value="张三" id="a1">张三&nbsp;&nbsp;
    <input type="checkbox" name="xzr" value="李四" id="a1">李四&nbsp;&nbsp;
    <input type="checkbox" name="xzr" value="王一" id="a1">王一&nbsp;&nbsp;
    <input type="checkbox" name="xzr" value="吴五" id="a1">吴五&nbsp;&nbsp;
    <input type="button" value="全选" id="b1" onclick="fncBtn('b1')">
    <br><br><b>第2组:</b>&nbsp;
    <input type="checkbox" name="xzr" value="沈七" id="a2">沈七&nbsp;&nbsp;
    <input type="checkbox" name="xzr" value="赵八" id="a2">赵八&nbsp;&nbsp;
    <input type="button" value="全选" id="b2" onclick="fncBtn('b2')">
    <br><br><b>第3组:</b>&nbsp;
    <input type="button" value="全选" id="b3">
    <br><br><b>第4组:</b>&nbsp;
    <input type="button" value="全选" id="b4">
    <br><br><b>第5组:</b>&nbsp;
    <input type="button" value="全选" id="b5">
    <br><br>
          </td>
        </tr>
        <tr> 
          <td>&nbsp;</td>
          <td><input name="Submit" type="submit" class="Button1" value="确 定"> <input name="Submit2" type="reset" class="Button1" value="重 置"> 
            <input type="button" name="Submit3" class="Button1" value="返 回" onClick="javascript:history.back();"></td>
        </tr>
      </table>
    <input type="hidden" name="line1" value="">
    <input type="hidden" name="line2" value="">
    </form>
    </body>
    </html>
      

  2.   

    不好意思,按钮名字没有改变吧?
    <html>
    <head>
    <title>揧壛埥廋夵&#35760;&#24405;</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <LINK href="../../inc/Style.css" rel=stylesheet type=text/css><script language="javascript">
    function submitit()
    {
    if(isEmpty(form1.file1.value))
    {
    alert("晬審晄擻&#20026;嬻");
    document.form1.file1.focus();
    return false;
    } var aa = 0;
    for(i=0;i<=form1.xzr.length-1;i++){
    if(form1.xzr[i].checked){
    aa = 1;
    break;
    }
    }
    if(aa == 0){
    alert("&#35831;&#36873;&#25321;壓&#36733;恖");
    form1.xzr[0].focus();
    return false;
    }
    }function isEmpty(sStr)
    {
      var oRegExp=/^[ ]*$/
      return oRegExp.test(sStr)
    }
    function fncBtn(btn)
    {
    if (btn=="b1")
    {
    if (document.form1.line1.value=="")
    {
    document.form1.elements[2].checked=true;
    document.form1.elements[3].checked=true;
    document.form1.elements[4].checked=true;
    document.form1.elements[5].checked=true;
    document.form1.line1.value=1;
    document.form1.b1.value="取消";
    }
    else
    {
    document.form1.elements[2].checked=false;
    document.form1.elements[3].checked=false;
    document.form1.elements[4].checked=false;
    document.form1.elements[5].checked=false;
    document.form1.line1.value="";
    document.form1.b1.value="全选";
    }

    }

    if (btn=="b2")
    {
    document.form1.a2.checked=true;
    if (document.form1.line2.value=="")
    {
    document.form1.elements[7].checked=true;
    document.form1.elements[8].checked=true;
    document.form1.line2.value=1;
    document.form1.b1.value="取消";
    }
    else
    {
    document.form1.elements[7].checked=false;
    document.form1.elements[8].checked=false;
    document.form1.line2.value="";
    document.form1.b1.value="全选";
    } }}</script>
    </head><body>
    <p align="center"><STRONG><FONT color=#006633 face=憊懱 size=+2> <U> 岞 嫟 懚 &#20648;</U></FONT></STRONG>&nbsp; 
    </p>
    <form action="ins.asp" method="post" enctype="multipart/form-data" name="form1" onsubmit="javascript:return submitit();">
      <table width="70%" border="0" align="center" cellpadding="0" cellspacing="10">
        <tr> 
          <td>晬審:</td>
          <td><input name="file1" type="file" class="CheckBox" size="50"></td>
        </tr>
        <tr> 
          <td>&#22791;拲:</td>
          <td><textarea name="nr" cols="59" rows="2" class="CheckBox"></textarea></td>
        </tr>
        <tr>
          <td width="15%">壓&#36733;恖丗</td>
          <td> 
    <b>戞1&#32452;丗</b>&nbsp;
    <input type="checkbox" name="xzr" value="&#24352;嶰" id="a1">&#24352;嶰&nbsp;&nbsp;
    <input type="checkbox" name="xzr" value="棝巐" id="a1">棝巐&nbsp;&nbsp;
    <input type="checkbox" name="xzr" value="墹堦" id="a1">墹堦&nbsp;&nbsp;
    <input type="checkbox" name="xzr" value="&#21556;屲" id="a1">&#21556;屲&nbsp;&nbsp;
    <input type="button" value="全选" id="b1" onclick="fncBtn('b1')">
    <br><br><b>戞2&#32452;丗</b>&nbsp;
    <input type="checkbox" name="xzr" value="捑幍" id="a2">捑幍&nbsp;&nbsp;
    <input type="checkbox" name="xzr" value="&#36213;敧" id="a2">&#36213;敧&nbsp;&nbsp;
    <input type="button" value="全选" id="b2" onclick="fncBtn('b2')">
    <br><br><b>戞3&#32452;丗</b>&nbsp;
    <input type="button" value="全选" id="b3">
    <br><br><b>戞4&#32452;丗</b>&nbsp;
    <input type="button" value="全选" id="b4">
    <br><br><b>戞5&#32452;丗</b>&nbsp;
    <input type="button" value="全选" id="b5">
    <br><br>
          </td>
        </tr>
        <tr> 
          <td>&nbsp;</td>
          <td><input name="Submit" type="submit" class="Button1" value="&#30830; 掕"> <input name="Submit2" type="reset" class="Button1" value="廳 抲"> 
            <input type="button" name="Submit3" class="Button1" value="曉 夞" onClick="javascript:history.back();"></td>
        </tr>
      </table>
    <input type="hidden" name="line1" value="">
    <input type="hidden" name="line2" value="">
    </form>
    </body>
    </html>
      

  3.   

    这里全选还是同样用复选框吧,更直观(不过你执意要用按钮的话稍改一下代码就行了)
    <input id=cks1 type=checkbox>a
    <input id=cks1 type=checkbox>b
    <input id=cks1 type=checkbox>c
    <input id=cks1 type=checkbox>d
    <input id=cks1 type=checkbox>e
    <input type=checkbox onclick="chk(cks1)" >全选
    <br>
    <input id=cks2 type=checkbox>A
    <input id=cks2 type=checkbox>B
    <input id=cks2 type=checkbox>C
    <input id=cks2 type=checkbox>D
    <input id=cks2 type=checkbox>E
    <input type=checkbox onclick="chk(cks2)"  id=checkbox1 name=checkbox1>全选
    <script>
    function chk(obj,isselected){
    len=obj.length;
    s=event.srcElement.checked;
    for(var i=0;i<len;i++){
    obj[i].checked=s
    }
    }
    </script>
      

  4.   

    因为我的是日文系统出现了乱码;下边这个应该没有乱码了
    <html>
    <head>
    <title>添加或修改记录</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <LINK href="../../inc/Style.css" rel=stylesheet type=text/css><script language="javascript">
    function submitit()
    {
    if(isEmpty(form1.file1.value))
    {
    alert("附件不能为空");
    document.form1.file1.focus();
    return false;
    } var aa = 0;
    for(i=0;i<=form1.xzr.length-1;i++){
    if(form1.xzr[i].checked){
    aa = 1;
    break;
    }
    }
    if(aa == 0){
    alert("请选择下载人");
    form1.xzr[0].focus();
    return false;
    }
    }function isEmpty(sStr)
    {
      var oRegExp=/^[ ]*$/
      return oRegExp.test(sStr)
    }
    function fncBtn(btn)
    {
    if (btn=="b1")
    {
    if (document.form1.line1.value=="")
    {
    document.form1.elements[2].checked=true;
    document.form1.elements[3].checked=true;
    document.form1.elements[4].checked=true;
    document.form1.elements[5].checked=true;
    document.form1.line1.value=1;
    document.form1.b1.value="取消";
    }
    else
    {
    document.form1.elements[2].checked=false;
    document.form1.elements[3].checked=false;
    document.form1.elements[4].checked=false;
    document.form1.elements[5].checked=false;
    document.form1.line1.value="";
    document.form1.b1.value="全选";
    }

    }

    if (btn=="b2")
    {
    document.form1.a2.checked=true;
    if (document.form1.line2.value=="")
    {
    document.form1.elements[7].checked=true;
    document.form1.elements[8].checked=true;
    document.form1.line2.value=1;
    document.form1.b2.value="取消";
    }
    else
    {
    document.form1.elements[7].checked=false;
    document.form1.elements[8].checked=false;
    document.form1.line2.value="";
    document.form1.b2.value="全选";
    } }}</script>
    </head><body>
    <p align="center"><STRONG><FONT color=#006633 face=宋体 size=+2> <U> 公 共 存 储</U></FONT></STRONG>&nbsp; 
    </p>
    <form action="ins.asp" method="post" enctype="multipart/form-data" name="form1" onsubmit="javascript:return submitit();">
      <table width="70%" border="0" align="center" cellpadding="0" cellspacing="10">
        <tr> 
          <td>附件:</td>
          <td><input name="file1" type="file" class="CheckBox" size="50"></td>
        </tr>
        <tr> 
          <td>备注:</td>
          <td><textarea name="nr" cols="59" rows="2" class="CheckBox"></textarea></td>
        </tr>
        <tr>
          <td width="15%">下载人:</td>
          <td> 
    <b>第1组:</b>&nbsp;
    <input type="checkbox" name="xzr" value="张三" id="a1">张三&nbsp;&nbsp;
    <input type="checkbox" name="xzr" value="李四" id="a1">李四&nbsp;&nbsp;
    <input type="checkbox" name="xzr" value="王一" id="a1">王一&nbsp;&nbsp;
    <input type="checkbox" name="xzr" value="吴五" id="a1">吴五&nbsp;&nbsp;
    <input type="button" value="全选" id="b1" onclick="fncBtn('b1')">
    <br><br><b>第2组:</b>&nbsp;
    <input type="checkbox" name="xzr" value="沈七" id="a2">沈七&nbsp;&nbsp;
    <input type="checkbox" name="xzr" value="赵八" id="a2">赵八&nbsp;&nbsp;
    <input type="button" value="全选" id="b2" onclick="fncBtn('b2')">
    <br><br><b>第3组:</b>&nbsp;
    <input type="button" value="全选" id="b3">
    <br><br><b>第4组:</b>&nbsp;
    <input type="button" value="全选" id="b4">
    <br><br><b>第5组:</b>&nbsp;
    <input type="button" value="全选" id="b5">
    <br><br>
          </td>
        </tr>
        <tr> 
          <td>&nbsp;</td>
          <td><input name="Submit" type="submit" class="Button1" value="确 定"> <input name="Submit2" type="reset" class="Button1" value="重 置"> 
            <input type="button" name="Submit3" class="Button1" value="返 回" onClick="javascript:history.back();"></td>
        </tr>
      </table>
    <input type="hidden" name="line1" value="">
    <input type="hidden" name="line2" value="">
    </form>
    </body>
    </html>