html:
<tr> <td width="20%" align="right">卷:</td> <td> <input type="hidden" value="${tcoupons.tctof_coupons}" name="tcoupons.tctof_coupons" id="tctof_coupons" /> <c:forEach var="cous" items="${coupon}"> <input type=‘checkbox‘ id="tctofcoupons" name=‘tctofcoupons‘ value="${cous[0]}" />${cous[1]} </c:forEach> </td> </tr>
jquery:
<script type="text/javascript"> $(function(){ $("input[name=‘tctofcoupons‘]").each(function(){//循环获取每个复选框值 var tctofcoupons=$(this).val(); var tctof=$("#tctof_coupons").val(); //获取卷拼接的字符串 var tc=[]; tc=tctof.split(","); //分割 for(var i=0;i<tc.length;i++){ if(tc[i]==tctofcoupons){ $(":checkbox[value=‘"+tc[i]+"‘]").prop("checked",true); //值相等,设置状态为选中 } } }); $("#save").click(function(){ var t="";//卷 $("input[name=‘tctofcoupons‘]:checked").each(function(){ //循环获取选中的每个复选框值 t+=$(this).val()+","; }); t=t.substring(0,t.lastIndexOf(",")); $("#tctof_coupons").val(t); $("#save").attr("disabled","disabled"); $.post("tcouponsFunctionAction_savetcoutoFunction",$("#form1").serialize(),function(result){ if(result=="1"){ alert("修改成功!"); location.href="tcouponsFunctionAction_gettcoutoFunctionList"; }else{ alert("修改失败!"); $("#save").removeAttr("disabled"); } }); }); }); </script>
时间: 2024-10-06 06:27:48