例如 我有个分页列表 每行的前面有个复选框  我的功能是选其中几个 然后点删除按钮删除这几行数据。
几个复选框的值怎么传给后台?

解决方案 »

  1.   

    1st 利用js取选择的复选框的值,组合成以特定字符如,分隔的字符串,采用form提交或者ajax的方式提交到后台处理2nd 直接利用form的方式提交,根据action中映射的数组或者利用 request.getParameterValues("ck")取选择的值(ck在这里是复选框的名字),然后操作
      

  2.   

    <html>
      <head>
        <base href="<%=basePath%>">
        <title>Struts2 复选框数据传值</title>
     <script type="text/javascript">
      function checkAll(){
       var listc = document.getElementsByName("listCheck");
       if(document.getElementById("CheckAll").checked==true){
        for(var i=0;i<listc.length;i++){
         listc[i].checked=true;
        }
       }else{
        for(var i=0;i<listc.length;i++){
         listc[i].checked=false;
        }
       }
      }
     </script>
      </head>
      <body>
        <form action="test" method="post">&nbsp;&nbsp;
         <input type="checkbox" name="CheckAll" id="CheckAll" onclick="checkAll()"/>全选<br/>
         <input type="checkbox" name="listCheck" value="111" />111<br/>
         <input type="checkbox" name="listCheck" value="222" />222<br/>
         <input type="checkbox" name="listCheck" value="333" />333<br/>
         <input type="checkbox" name="listCheck" value="444" />444<br/>
         <input type="checkbox" name="listCheck" value="555"/>555 <br/>
         <input type="submit" value="提交"/>
        </form>
        <c:forEach items="${listCheck }" var="che">
         <c:out value="${che }" /> &nbsp;&nbsp; &nbsp;&nbsp;
        </c:forEach>
      </body>
    </html>
    package com.okttl.web.action;import java.util.List;import com.okttl.entity.Users;
    import com.opensymphony.xwork2.ActionSupport;public class CheckBoxTestAction extends ActionSupport { private List listCheck;
     
     public List getListCheck() {
      return listCheck;
     }
     public void setListCheck(List listCheck) {
      this.listCheck = listCheck;
     }
     public String findAll(){
      System.out.println("我的复选框提交测试");
      System.out.println(listCheck);
      return SUCCESS;
     }
    }
      

  3.   


    建议楼主还是看下javascript,这个是很基础的知识,还是打好基础比较重要。
      

  4.   

    写个Js函数,将选中的记录的ID用逗号分隔传到后台,在后台分隔字符串,取得所有要删除的记录ID,然后delete
      

  5.   

    后台:private String[] listCheck;
    生成set 和 get方法。看能不能打印出来。
      

  6.   

    给checkbox 加个id="cbo"+你那张表里的主键 " name 设为一样 value设为你需要的字段
    根据name取得集合  然后循环遍历  根据id取得各个checkbox 也就取到各个checkbox里的值了
      

  7.   

    前台使用js取值封装
        可以封装成字符串(可以使用下划线连接) 或 List后台
       字符串:分割取值
       List:迭代
      

  8.   

    提交前 用JS 循环判断整个form的多选框是否被选中然后将选中的记录的主键值 拼起来传入后台传的时候 你可以选择用隐藏域 或者直接拼在请求URL后面
      

  9.   

    把所有checkBox的name弄从一样的,value不一样,然后在action里面用一个数组接收
      

  10.   

    把每一个复选框的name都设成同一个名字比如checkbox,让他们的value值为每个数据的关键值,比如Id.
    在服务器端action定义一个String[] checkbox,然后循环遍历出每一项的值