麻烦给具checkbox 多选取值的例子

lyixian 2013-04-26 03:02:55
看图片啦,就是勾选后的一项,提交的时候检测右边的text有没有填写。用jqeury的。。。。麻烦高人给个js代码,谢谢!




我当前的html表单部分是:
<table class=tableframe style=word-break:break-all width="98%" align=center id="contenttableid" >
<tbody>
<tr class=listtitle>
<td class=listcelltitle align=middle islock="true" width="33px"></td>
<td class=listcelltitle align=middle height="25" width=200><div> 物料名称</div></td>
<td class=listcelltitle align=middle height="25" width=100><div> 最小发注量</div></td>
<td class=listcelltitle align=middle height="25" width=100><div> 采购周期</div></td>

</tr>
<!-- BEGIN BXBK -->
<tr class=listrow1 bgcolor="{bgcolor}" onClick="changecolor(this,'#FFEA96','1','#FFEA96');" >
<td class=listcellrow style='WIDTH: 10px;'><input type='checkbox' id=arrlabel name='checknote[{i}]' value='{vmat_name}' ></td>
<td class=listcellrow noWrap align=left height='23' >{vmat_name}</td>
<td class=listcellrow noWrap align=left height='23' ><input type="text" name="mat_zxfzl[]" id="mat_zxfzl[{i}]" size="12"></td>
<td class=listcellrow noWrap align=left height='23' ><input type="text" name="mat_cgzq[]" id="mat_cgzq[{i}]" size="12">(天)</td>
</tr>
<!-- END BXBK -->
</tbody>
</table>
...全文
223 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
lyixian 2013-04-27
  • 打赏
  • 举报
回复
引用 8 楼 thc1987 的回复:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<TITLE> New Document </TITLE>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
function validate() {
	var $trs = $('#contenttableid tr');

	$trs.each(function(){
		var $tr = $(this);
		if($tr.find("input[type='checkbox']").attr('checked')) {
			var $texts = $tr.find("input[type='text']");
			$texts.each(function(){
			if(!this.value) {
				alert('未填写值')
				}
			});
		}
	});
	
}
</script>
</HEAD>

<BODY>
<table class=tableframe style=word-break:break-all width="98%" align=center id="contenttableid" >
			  <tbody> 
			  <tr class=listtitle>
			       <td class=listcelltitle align=middle  islock="true" width="33px"></td>
				   <td  class=listcelltitle align=middle height="25"  width=200><div> 物料名称</div></td>
				   <td  class=listcelltitle align=middle height="25"  width=100><div> 最小发注量</div></td>
				   <td  class=listcelltitle align=middle height="25"  width=100><div> 采购周期</div></td>
				
				  </tr>
				  <!-- BEGIN BXBK -->
				  <tr class=listrow1   bgcolor="{bgcolor}"  >
					<td class=listcellrow style='WIDTH: 10px;'><input type='checkbox' id=arrlabel name='checknote[{i}]' value='ddddd' ></td>
					<td class=listcellrow noWrap align=left height='23' >物料名称aaa</td> 
					<td class=listcellrow noWrap align=left height='23' ><input type="text" name="mat_zxfzl[]" id="mat_zxfzl[{i}]" size="12"></td> 
					<td class=listcellrow noWrap align=left height='23' ><input type="text" name="mat_cgzq[]" id="mat_cgzq[{i}]" size="12">(天)</td> 
				</tr>
				<!-- END BXBK -->
		</tbody>
		</table>


		<INPUT TYPE="button" VALUE="验证" ONCLICK="validate()">
</BODY>
</HTML>
感谢,搞定
猿敲月下码 2013-04-27
  • 打赏
  • 举报
回复
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<TITLE> New Document </TITLE>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
function validate() {
	var $trs = $('#contenttableid tr');

	$trs.each(function(){
		var $tr = $(this);
		if($tr.find("input[type='checkbox']").attr('checked')) {
			var $texts = $tr.find("input[type='text']");
			$texts.each(function(){
			if(!this.value) {
				alert('未填写值')
				}
			});
		}
	});
	
}
</script>
</HEAD>

<BODY>
<table class=tableframe style=word-break:break-all width="98%" align=center id="contenttableid" >
			  <tbody> 
			  <tr class=listtitle>
			       <td class=listcelltitle align=middle  islock="true" width="33px"></td>
				   <td  class=listcelltitle align=middle height="25"  width=200><div> 物料名称</div></td>
				   <td  class=listcelltitle align=middle height="25"  width=100><div> 最小发注量</div></td>
				   <td  class=listcelltitle align=middle height="25"  width=100><div> 采购周期</div></td>
				
				  </tr>
				  <!-- BEGIN BXBK -->
				  <tr class=listrow1   bgcolor="{bgcolor}"  >
					<td class=listcellrow style='WIDTH: 10px;'><input type='checkbox' id=arrlabel name='checknote[{i}]' value='ddddd' ></td>
					<td class=listcellrow noWrap align=left height='23' >物料名称aaa</td> 
					<td class=listcellrow noWrap align=left height='23' ><input type="text" name="mat_zxfzl[]" id="mat_zxfzl[{i}]" size="12"></td> 
					<td class=listcellrow noWrap align=left height='23' ><input type="text" name="mat_cgzq[]" id="mat_cgzq[{i}]" size="12">(天)</td> 
				</tr>
				<!-- END BXBK -->
		</tbody>
		</table>


		<INPUT TYPE="button" VALUE="验证" ONCLICK="validate()">
</BODY>
</HTML>
苹果没有皮 2013-04-26
  • 打赏
  • 举报
回复
先得到checkbox checked的tr元素

$(function(){
    $trs = $("input:checked").parentsUntil("tr").parent();
    $.each($trs, function(index1, tr){
        $.each($(this).find("td:gt(1)"), function(index2, td){
            //这里就可以对每个td里面的内容进行判断了,我这里选择的td是从第三列开始的,如果要变的话你就改find()这边的选择器好了
        });
    });
});
ac382717036 2013-04-26
  • 打赏
  • 举报
回复
$.each($("input[type='checkbox']"), function (i, o) { if ($(this).attr("checked") == true) { var txt1 = $(this).parent("td").siblings("td").find("mat_zxfzl[{i}]").val(); alert(txt1); var txt2 = $(this).parent("td").siblings("td").find("mat_cgzq[{i}]").val(); alert(txt2); } });
lyixian 2013-04-26
  • 打赏
  • 举报
回复
引用 3 楼 zzgzzg00 的回复:
先获取checkbox的父元素 然后获取nextSibling直到要的元素试试
哈哈,完全不懂你的意思。
似梦飞花 2013-04-26
  • 打赏
  • 举报
回复
先获取checkbox的父元素 然后获取nextSibling直到要的元素试试
lyixian 2013-04-26
  • 打赏
  • 举报
回复
太低级了,没人愿意答?
lyixian 2013-04-26
  • 打赏
  • 举报
回复

87,992

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧