复选框初始值全部为0,Text控件初始值为0000。当触发onclick事件时判断,如果当前复选框被选中那么它的值救改为1,否则为0。同时修改Text控件对应的位。数据提交时读取Text的数据即可。

解决方案 »

  1.   

    这是第一个问题的回答,先给100分吧.
    <html>
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
        <title>福利</title>
      <SCRIPT>
    <!--
    var Insur_weals = 0;
    function application_onsubmit() {
    var len = select.Insur_weal.length;
    for(var i = 0; i < len; i++)
    {
    if(select.Insur_weal[i].checked)
    {
    Insur_weals = Insur_weals | (1 << i);
    }
    }
    application.Insur_weals.value = Insur_weals;
    }//-->
    </SCRIPT>
    </head>
      <body>
        <form name="select">
          <table>
            <tr>
              <td width="133" height="24" align="right">
                <div align="left">
                  <p align="right">福利(保险):
                </div>
              <td width="190" height="24"><input type="checkbox" name="Insur_weal" value="1">养老保险 
                <input type="checkbox" name="Insur_weal" value="1">医疗保险</td>
              <td width="178" align="right" height="24"><input type="checkbox" name="Insur_weal" value="1">工伤保险 
                <input type="checkbox" name="Insur_weal" value="1">失业保险</td>
          </table>
        </form>
        <form name="application" method="POST" action="http://localhost:1024/" onsubmit="return application_onsubmit()">
          <p><input type="submit" value="提交"></p>
          <input type="hidden" name="Insur_weals"<html>
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
        <title>福利</title>
      <SCRIPT>
    <!--
    var Insur_weals = 0;
    function application_onsubmit() {
    var len = select.Insur_weal.length;
    for(var i = 0; i < len; i++)
    {
    if(select.Insur_weal[i].checked)
    {
    Insur_weals = Insur_weals | (1 << i);
    }
    }
    application.Insur_weals.value = Insur_weals;
    }//-->
    </SCRIPT>
    </head>
      <body>
        <form name="select">
          <table>
            <tr>
              <td width="133" height="24" align="right">
                <div align="left">
                  <p align="right">福利(保险):
                </div>
              <td width="190" height="24"><input type="checkbox" name="Insur_weal" value="1">养老保险 
                <input type="checkbox" name="Insur_weal" value="1">医疗保险</td>
              <td width="178" align="right" height="24"><input type="checkbox" name="Insur_weal" value="1">工伤保险 
                <input type="checkbox" name="Insur_weal" value="1">失业保险</td>
          </table>
        </form>
        <form name="application" method="POST" action="http://localhost:1024/" onsubmit="return application_onsubmit()">
          <p><input type="submit" value="提交"></p>
          <input type="hidden" name="Insur_weals" value="0">
        </form>
      </body>
    </html>
      

  2.   

    这下是全部的答案了,注意那个application.Insur_weals.value是十进制值,它不可以接受二进制的值,使用时请注意。14是二进制的1110,所以第二,三,四个选项选中。
    好了,二百分,拿来吧,这几天正穷。
    <html>
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
        <title>福利</title>
      <SCRIPT>
    <!--
    var Insur_weals = 0;
    function application_onsubmit() {
    var len = select.Insur_weal.length;
    for(var i = 0; i < len; i++)
    {
    Insur_weals = 0;
    if(select.Insur_weal[i].checked)
    {
    Insur_weals = Insur_weals | (1 << i);
    }
    }
    application.Insur_weals.value = Insur_weals;
    }
    function initSelect()
    {
    Insur_weals = application.Insur_weals.value;
    var len = select.Insur_weal.length;
    for(var i = 0; i < len; i++)
    {
    if(Insur_weals & (1<<i))select.Insur_weal[i].checked=true;
    }
    }//-->
    </SCRIPT>
    </head>
      <body onload="initSelect()">
        <form name="select">
          <table>
            <tr>
              <td width="133" height="24" align="right">
                <div align="left">
                  <p align="right">福利(保险):
                </div>
              <td width="190" height="24"><input type="checkbox" name="Insur_weal" value="1">养老保险 
                <input type="checkbox" name="Insur_weal" value="1">医疗保险</td>
              <td width="178" align="right" height="24"><input type="checkbox" name="Insur_weal" value="1">工伤保险 
                <input type="checkbox" name="Insur_weal" value="1">失业保险</td>
          </table>
        </form>
        <form name="application" method="POST" action="http://localhost:1024/" onsubmit="return application_onsubmit()">
          <p><input type="submit" value="提交"></p>
          <input type="hidden" name="Insur_weals" value="14">
        </form>
      </body>
    </html>
      

  3.   

    Insur_weals = Insur_weals | (1 << i); ???
      

  4.   

    一般在Post的Jsp或Servlet上进行取值:
    JSP或Html:
    <form name="testform" action="save.jsp" method="post">   //加入
    ...
    <tr>                                
     <td width="133" height="24" align="right">                                
      <div align="left">              
       <p align="right">福利(保险):             
       </div>             
       <td width="190" height="24">                    
       <input type="checkbox" name="Insur_weal" value="1">养老保险                  
       <input type="checkbox" name="Insur_weal" value="1">医疗保险                  
       </td>                     
       <td width="178" align="right" height="24">                    
       <input type="checkbox" name="Insur_weal" value="1">工伤保险                  
       <input type="checkbox" name="Insur_weal" value="1">失业保险                    
       </td>                      
      </tr> 
    ...
    </from>  //加入在save.jsp中:
    <%
    String sInsur_weal = "";
    String[] str=request.getParameterValues("Insur_weal");
    for (int i=0; i<str.length; i++) {
      if (str[i] == null) {
        sInsur_weal := sInsur_weal + "0";
      } else {
        sInsur_weal := sInsur_weal + "1";
      }
    }
    System.out.println(sInsur_weal);  // 返回"0010"或"1110"等值
    //@todo: 存储sInsur_weal变量的值到数据库
    %>
      

  5.   

    我的第一次回答在粘贴源代码时出错了,第二次回答正确。
    Insur_weals = Insur_weals | (1 << i); 是位运算啊。
      

  6.   

    奇怪啊。for (int i=0; i<str.length; i++) {
      if (str[i] == null) {
        sInsur_weal = sInsur_weal + "0";
      } else {
        sInsur_weal = sInsur_weal + "1";
      }
    }
    只能够插入“1”直,而不能够插入“0”哦。
      

  7.   

    这是接收的一唯sInsur_weal的,要是二唯的呢?也就是说,如果有多个sInsur_weal要传递给save.jsp页面,又该怎么接收呢?还有,接收了如何拆分呢?谢谢,想到了问问!
      

  8.   


      if (operType!=null&&operType.equals("2"))
      {
        String delID[];
        delID = request.getParameterValues("sInsur_weal");
        if (delID!=null)
        {
          ArrayList delArr = new ArrayList();
          for (int j=0;j< delID.length;j++)
          {
            delArr.add(delID[j]);
          }
         }   }
    这样就可以接受放在数组delID里面
    并且放入ArrayList 里面
      

  9.   

    为什么要是二维的放在值
    <input type="checkbox" name="Insur_weal" value="1,x">养老保险        
    逗号分割传上去就可以
    save页面上通过数组取值后
    再进行分割字符串
      

  10.   

    不能插入0是因为
    checkbox不将为选中的提交上去
    只提交选中的,这是简单的html的知识
      

  11.   

    stoneopen1(d) 
    我的方法(我的第二个回贴)是简单而且可行的,你怎么还……,还不????