js遍历赋值

<table id="example2" class="table table-bordered table-hover">
		<thead>
		<tr>
			<th class="t_c"><input type="checkbox" onclick="checkListAll()" id="toppcheckbox22"></th>
			<th>个人账户状态</th>
			<th style="text-align: left">维护年限</th>
		</tr>
		</thead>
		<tbody>
		<c:forEach items="${pagView.viewList}" var="pz" varStatus="status">
			<tr class="needredcolorr">
				<td align="center"><input type="checkbox" id="checkboxx" value="${pz.grzh }" name="grzh"/></td>
				<td style="text-align:left"> <gjj:dataCache zddm="GRZHZT" zddmz="${pz.grzhzt }" /></td>
				<td>
					<div class="nianling">${pz.nianling}年</div>
				</td>

			</tr>
		</c:forEach>
		</tbody>
	</table>

//全选 、 反全选
function checkListAll() {
		var flag = $("#toppcheckbox22").is(':checked');
		$(".needredcolorr input[id='checkboxx']").each(function(i) {
			if (!$(this).is(":disabled")) {
				var grzh = $(this).val();
				if (flag) {
					$(this).prop('checked', true);
					$(this).attr('checked', true);
					// if(grzhs.indexOf(grzh)<0) {
					// 	grzhs.push(grzh);
					// }
					if(!grzhs[grzh]) {
						grzhs[grzh]="0";
					}
				} else {
					$(this).prop('checked', false);
					$(this).removeAttr("checked");
					// grzhs.remove(grzh);
					delete grzhs[grzh];
				}
			}
		});
	}

//给td赋值
	$(function () {
		$('.needredcolorr input[type="checkbox"]').each(function () {
			//获取tr 的Id :<tr name="project" id="1114"> 针对每一个tr,该tr都有一个id属性,该属性的值为项目id
			var nl = grzhs[$(this).val()];
			console.log(nl)
			if(nl) {
				if (nl != "0") {
					$(this).parents("tr").eq(0).find('.nianling').text(nl+ '年');
				}
			}
		})
	})

<table id="example2" class="table table-bordered table-hover">
		<thead>
		<tr>
			<th class="t_c"><input type="checkbox" onclick="checkListAll()" id="toppcheckbox22"></th>
			<th>个人账户状态</th>
			<th style="text-align: left">维护年限</th>
		</tr>
		</thead>
		<tbody>
		<c:forEach items="${pagView.viewList}" var="pz" varStatus="status">
			<tr class="needredcolorr">
				<td align="center"><input type="checkbox" id="checkboxx" value="${pz.grzh }" name="grzh"/></td>
				<td style="text-align:left"> <gjj:dataCache zddm="GRZHZT" zddmz="${pz.grzhzt }" /></td>
				<td>
					<div class="form-group com-item-form-group ml-0">
						<select class="form-control select2" name="nianling" id="nianling">
							<option>请选择</option>
							<option value="1">1</option>
							<option value="2">2</option>
						</select>

					</div>
				</td>

			</tr>
		</c:forEach>
		</tbody>

//checkbox反显
	$(function () {
		$('.needredcolorr input[type="checkbox"]').each(function () {
			var nl = grzhs[$(this).val()];
			if(nl){
				if(nl!="0"){
					$(this).parents("tr").eq(0).find("select").val(nl);
				}
			}
		})
	})
//选择人员 checkbox 显示删除

$("#example2 tbody tr").each(function() {
		$(this).find("td").not(":first").click(function() {
			// var $td = $(this).parents("tr").eq(0).find('.zjhm')
			// var zjhm = $td.text();
			// if($td.get(0) && !zjhm){
			// 	showMessage(2,"证件号码不能为空,请完善信息后再进行缴存!");
			// 	return false;
			// }
			var che = $(this).parents("tr").eq(0).find('#checkbox');
			var grzh = che.val();
			if (grzhs[grzh] == "0") {
				che.prop('checked', false)
				delete grzhs[grzh];//同时删除key和value
			} else {
				che.prop('checked', true)
				grzhs[grzh] = "0";
			}
		})
	})
//请求后端接口
function tianjia(th) {
        if (jQuery("#hmd_add_from").valid()) {
            // $(th).attr({"disabled": "disabled"});
            // $(th).text("提交中...");
            var keys = Object.getOwnPropertyNames(grzhs);
            var values = [];
            for(var i = 0; i< keys.length;i++){
                var k = keys[i];
                values.push(grzhs[k]);
            }
            ajaxPage.post("../zgnlcxpz/zgnlcxpzSave.data", 
            //grzh 个人账号   clnx 超龄年限  后端方法中接收这俩个值
ajaxForm.serialize("hmd_add_from")+"&grzh="+keys.join(",")+"&clnx="+ values.join(","),
                function (data) {
                    var result = $.parseJSON(data);
                    if (result.rsp_code == '<%=Constant.RSP_CODE_00%>') {
                        $('#plbh').val(result.rsp_desc);
                        //加载电子档案
                        ajaxPage.load("tab_3", "../dzda/dzdaEdit.data", "ssxt=<%=DAConstant.DZSSXT_P4%>&ywlsh=" + result.rsp_desc);
                        next();
                    } else {
                        showMessage(2, result.rsp_desc);
                        // $(th).removeAttr("disabled");
                        // $(th).text("保存");
                    }
                })
        }
    }

这辈子坚持与不坚持都不可怕,怕的是独自走在坚持的道路上!!!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值