//编辑数据渲染$("#zh_update").click(function(){if(checknum==1){$(".zh_update").show();//获取当前选中的参数//ajax请求获取数据把id传过去 编辑前的渲染数据$.ajax({url:"${pageContext.request.contextPath}/orgbank/getById",type:"post",data:{ "id":$(".thisID").html()},datatype:"json",success:function(res){console.log(res);$(".upd_code").val(res.bzuhziCode);// $(".upd_khyh").val(res.bzuzhiBankId);$(".upd_money_type").val(res.amonntGuojiCode);$(".upd_name").val(res.zuzhiName);$(".upd_yhcode").val(res.bzuhziAcountNo); $("#sel_bank").find("option[value='"+res.bzuzhiBankId+"']").attr("selected",true); }});}else if(checknum==0){$("#modal-demo").modal("show");$(".msg-content").html("请选择一条内容!");}else{$("#modal-demo").modal("show");$(".msg-content").html("请选择一条内容!");}});
$("#sel_bank").find("option[value='"+res.bzuzhiBankId+"']").attr("selected",true); ajax返回的值给下拉框,显示出默认选中的那个下拉框的值
jsp 上面的select选项
<select id="sel_bank"><c:forEach items="${bankName}" var="a"><option value=${a.bankId }> ${a.bankName }</option></c:forEach></select>
select id="sel_bank"
iems是自己从数据库中查出来的。