日期:2014-05-16  浏览次数:20488 次

有关javascript中checkbox的相关问题。麻烦了。(所有分了)
代码如下。
需要实现获取选中checkbox所在行的所有数据。并且通过Ajax的方式传递到后台。

<table><tr>
<td  align="center"><input type="checkbox" id="checktd<%=i%>" name="checktd" /></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>


</tr></table>

------解决方案--------------------
将每条数据的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,