将每条数据的id绑定到复选框的value上,然后提交选中的id集合
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" id="html">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
$(function(){
$("#btn_submit").click(function(){
var data=[];
$("input[name='cb']:checked").each(function(index, element) {
data.push($(this).val());

});
alert(data.join(','))
});
})
</script>
</head><body id="body">
<table>
<tr>
     <th>选择</th>
        <th>姓名</th>
        <th>年龄</th>
    </tr>
<tr>
     <td><input type="checkbox" value="1" name="cb"/></td>
        <td>小王</td>
        <td>20</td>
    </tr>
    <tr>
     <td><input type="checkbox" value="2" name="cb"/></td>
        <td>小马</td>
        <td>30</td>
    </tr>
</table>
<input type="button" value="提交" id="btn_submit"/>
</body>
</html>

解决方案 »

  1.   

    您这样是获取的checkbox中的value.
    我的checkbox就一个
    通过for循环来动态增加的.
      

  2.   


    能把你for循环出来的页面代码贴出来吗
      

  3.   


    能把你for循环出来的页面代码贴出来吗
        <form id="shdform" action="/hhcx/SaveDdgzAction.do" method="post" >
                    <input type="hidden" name="strs" id="strs" value="<%=strs%>"/>   
                    <input type="hidden" name="xmh" id="xmh" value="<%=xmh%>"/>      
                    <input type="hidden" name="fgs"  id="fgs" value="<%=fgs%>"/>
                     <input type="hidden" name="gys" id="gys"  value="<%=gys%>"/> 
                      <input type="button" id="saveshd" value="保存修改" onclick="deal()"/>        
                    <p style="font-size: 14"> 箱码号  <%=xmh %>  </p>
                    
                    <table  cellpadding="0" cellspacing="0" border="0" class="display" id="example">
                        <thead>
                            <tr>
                                <th>选择</th>
                               <th rowspan="2" ></th>
                               <th rowspan="2" ></th>
                                <th rowspan="2"></th>
                                <th rowspan="2"></th>
                                <th rowspan="2"></th>
                                <th rowspan="2"></th>    
                                <th rowspan="2"></th>
                                <th rowspan="2"></th>
                                <th rowspan="2"></th>  
                            </tr>
                        </thead>            
                        <tfoot>
                            <tr>
                                <th>总计:</th>
                                <th></th>
                                <th></th>
                                <th></th>
                                <th></th>
                                <th></th>
                                <th></th>                     
                                <th></th>
                                <th></th> 
                                <th></th> 
                            </tr>
                        </tfoot>
                        <tbody>
                            <%
                                for (int i = 0; i < ddhead.size(); i++) {
                                    InputDetailHead dd = (InputDetailHead) ddhead.get(i);
                                    String rowno = dd.getRowno();
                                    String seqno = dd.getSeqno();
                                    String com_code=dd.getCom_code();
                                    String name = dd.getName();
                                    String xstm = dd.getXstm();
                                    double shjs = dd.getShjs();
                                    double shls = dd.getShls();
                                    double shsl = dd.getShsl();
                                    double zxsled = dd.getZxsl();
                            %>
                            <tr>
        <td  align="center"><input type="checkbox" id="checktd<%=i%>" name="checktd"  onclick="showtable(this)"/></td>                    
                                <td>
                                    <%=seqno%>
                                    <input type="hidden" name="seqno" id="seqno<%=i%>" value="<%=seqno%>"/>
                                </td>
                                 <td>
                                    <%=rowno%>
                                    <input type="hidden" name="rowno" id="rowno<%=i%>" value="<%=rowno%>"/>
                                </td>
                                <td >
                                    <%=com_code%>
                                    <input type="hidden" name="com_code" value="<%=com_code%>"/> 
                                </td>
                                <td >
                                    <%=name%>
                                    <input type="hidden" name="name" value="<%=name%>"/> 
                                </td>                            <td>
                                    <%=xstm%>       
                                    <input type="hidden" name="xstm" value="<%=xstm%>"/> 
                                </td>
                                <td align="center">
                                    <input type="text"   id="unshls<%=i%>" name="unshls" disabled="disabled"   readonly="readonly"  size="8"   />                                
                                </td>    
                                <td align="center">
                                    <input type="text"   id="zxsled<%=i%>" name="zxsled" disabled="disabled"   readonly="readonly"  size="8" value="<%=zxsled%>" />                                
                                </td>         
                                 <td align="center">
                                    <%=shsl%>   
                                    <input type="hidden"  id="shls<%=i%>"  name="shls" value="<%=shsl%>"/> 
                                </td>     
                                 <td align="center">
                                    <input  type="text" id="zxsl<%=i%>"   name="zxsl"  size="8" onchange="setsl(this)"  value="0"/>
                                </td>              
                            </tr>
                            <%
                                }
                            %>
                           
                        </tbody>
                    </table>
                </form>
      

  4.   

    function showtable(obj){

    if($(obj).prop('checked') == true){
    var str = '';
    var input = $(obj).closest('tr').find(":input[type!='checkbox']");
    for (var i = 0; i < input.length; i++) {
    str += $(input[i]).val();
    };
    console.log(str)
    }
    }
      

  5.   


    感谢。
    但是我这个方法是在这里调用的。
    拼接的值需要丢到data中传递到后台的。
    如果绑定控件了。在这里就弄不了$.ajax({
    type : "POST",
    url : '/hhcx/SaveDdgzAction.do',
    data : getRows(),
      

  6.   

    是多选还是单选?楼主是想在提交时自动判断页面哪行被选中,然后把选中行的值拼串传给后台吗?方法是写在getrows里?
    我有段原始的代码,你可以参考这个思路改一下
    function getrows(){
    var data="";
    //判断有多少行
    for (var i = 0; i < document.shdform.checktd.length; i++) {
    //判断选中行
    if(document.shdform.checktd[i].checked){
                               data=data + document.shdform.seqno[i].value;
                               data=data + document.shdform.rowno[i].value;
    //...累加其他字段
    }
    }
    returm data;
    }