循环获取多选框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 width="5%">
						<input type='checkbox' value="" />
					</th>
					<th width="10%" id="phCol">
						<span id="jh">批号</span>
					</th>
					<th width="13%" id="gzsbhCol">
						<span id="sxbh">编号</span>
					</th>
					<th width="13%" id="dsrCol">
						<span id="dsr">当事人</span>
					</th>
				</tr>

				<tr>
					<th width="5%">
						<input type='checkbox' value="11" />
					</th>
					<th width="10%" id="phCol">
						<span id="jh">11</span>
					</th>
					<th width="13%" id="gzsbhCol">
						<span id="sxbh">11</span>
					</th>
					<th width="13%" id="dsrCol">
						<span id="dsr">11</span>
					</th>
				</tr>

				<tr>
					<th width="5%">
						<input type='checkbox' value="22" />
					</th>
					<th width="10%" id="phCol">
						<span id="jh">22</span>
					</th>
					<th width="13%" id="gzsbhCol">
						<span id="sxbh">22</span>
					</th>
					<th width="13%" id="dsrCol">
						<span id="dsr">22</span>
					</th>
				</tr>

				<tr>
					<th width="5%">
						<input type='checkbox' value="33" />
					</th>
					<th width="10%" id="phCol">
						<span id="jh">33</span>
					</th>
					<th width="13%" id="gzsbhCol">
						<span id="sxbh">33</span>
					</th>
					<th width="13%" 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>

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值