将每条数据的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>
<!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>
解决方案 »
- javascript中的恶'&'和 ‘>>>=’是代表什么意思
- 一个基于JavaScript的Web绘制图表工具
- 谁能知道bing网站选择更城市弹出的窗口如何实现吗?
- showModalDialog打开的页面用select重新加载页面的问题,急!
- 怎样才能实现2个下拉框的内容相关联?...选中一个下拉框的内容,第二个下拉框的内容随之而变,与其相对应
- JS右键怎样实现多级菜单
- 如何在js 引用合并后的单元格 ??? 急
- 请问怎样向一个txt文件的最后添加新行,谢谢?
- 怎样判断一个表单已经被用户改变?
- Javascript 递归代替循环中遇到的问题。求助!!
- table中动态生成的td列 怎么取不到呢
- js时间相减
我的checkbox就一个
通过for循环来动态增加的.
能把你for循环出来的页面代码贴出来吗
能把你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>
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)
}
}
感谢。
但是我这个方法是在这里调用的。
拼接的值需要丢到data中传递到后台的。
如果绑定控件了。在这里就弄不了$.ajax({
type : "POST",
url : '/hhcx/SaveDdgzAction.do',
data : 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;
}