循环获取多选框checkbox的value值
//获取id为checkboxTable的table标签当中所有被选中的多选框checkbox
$("#checkboxTable input:checkbox:checked").each(function() {
});
$("#checkboxTable input[type=checkbox]").each(function(){
if($(this).attr("checked")){
}
});
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/jquery-1.4.js"></script>
</head>
<body>
<div>
<table class="tableStyle" id="checkboxTable">
<tr>
<th>
<input type='checkbox' value="" />
</th>
<th id="phCol">
<span id="jh">批号</span>
</th>
<th id="gzsbhCol">
<span id="sxbh">编号</span>
</th>
<th id="dsrCol">
<span id="dsr">当事人</span>
</th>
</tr>
<tr>
<th>
<input type='checkbox' value="11" />
</th>
<th id="phCol">
<span id="jh">11</span>
</th>
<th id="gzsbhCol">
<span id="sxbh">11</span>
</th>
<th id="dsrCol">
<span id="dsr">11</span>
</th>
</tr>
<tr>
<th>
<input type='checkbox' value="22" />
</th>
<th id="phCol">
<span id="jh">22</span>
</th>
<th id="gzsbhCol">
<span id="sxbh">22</span>
</th>
<th id="dsrCol">
<span id="dsr">22</span>
</th>
</tr>
<tr>
<th>
<input type='checkbox' value="33" />
</th>
<th id="phCol">
<span id="jh">33</span>
</th>
<th id="gzsbhCol">
<span id="sxbh">33</span>
</th>
<th id="dsrCol">
<span id="dsr">33</span>
</th>
</tr>
</table>
<input type="button" value="审 批(A)" onclick="showSPWin5()" />
</div>
<script>
function showSPWin5() {
var slbh = "";
//方法一
//获取id为checkboxTable的table标签当中所有被选中的多选框checkbox
$("#checkboxTable input:checkbox:checked").each(function() {
//将选中的checkbox当中的value值进行拼接
slbh = slbh + "," + $(this).val();
//alert(slbh) ,11,22,33
});
//方法二
// $("#checkboxTable input[type=checkbox]").each(function(){
// if($(this).attr("checked")){
// slbh = slbh + "," + $(this).val();
// }
//
// });
if(slbh.length > 0) {
//截取字符串,将索引为0的给去除掉 索引0的值为 ,
slbh = slbh.substring(1, slbh.length);
//alert(slbh) 11,22,33
//发送ajax请求到后台
//slbh.replace(",", "----") 将拼接的字符串当中,使用----替代,或者用于sql批量查询
}
}
</script>
</body>
</html>