jsp 分类级联查询 selected
<li>所在市:</li> <li> <select name="cityId" class="input2" id="cityId"> <option value=''>---请选择---</option> <s:iterator value="queryAddressList" var="fatherV"> <s:if test="cityId == id"> <option value="<s:property value='id'/>" selected="selected"><s:property value="cityName"/></option> </s:if> <s:else> <option value="<s:property value='id'/>"><s:property value="cityName"/></option> </s:else> <s:iterator value="counties" var="sonV"> <input type="hidden" name ="father_<s:property value='#fatherV.id'/>" value="<s:property value='#sonV.countyName'/>_<s:property value='#sonV.id'/>"/> <s:iterator value="blocks" var="grandsonV"> <input type="hidden" name ="son_<s:property value='#grandsonV.id'/>" value="<s:property value='#grandsonV.blockName'/>_<s:property value='#grandsonV.id'/>"/> </s:iterator> </s:iterator> </s:iterator> </select> </li>
<li>所在区:</li> <li> <select name="countyId" class="input2" id="countyId"> <option value="0">---请选择---</option> <s:iterator value="queryAddressList"> <s:if test="cityId == id"> <s:iterator value="counties"> <s:if test="countyId == id"> <option value="<s:property value="id" />" selected="selected"><s:property value="countyName" /></option> </s:if> <s:else> <option value="<s:property value="id" />"><s:property value="countyName" /></option> </s:else> </s:iterator> </s:if> </s:iterator> </select> </li>
<li>所在区域:</li> <li> <select name="blockId" class="input2" id="blockId"> <option value="0" selected="selected">-- 请选择 --</option> <s:iterator value="queryAddressList"> <s:if test="cityId == id"> <s:iterator value="counties"> <s:if test="countyId == id"> <s:iterator value="blocks"> <s:if test="blockId == id"> <option value="<s:property value="id" />" selected="selected"><s:property value="blockName" /></option> </s:if> <s:else> <option value="<s:property value="id" />"><s:property value="blockName" /></option> </s:else> </s:iterator> </s:if> </s:iterator> </s:if> </s:iterator> </select> </li>
$(function(){ /** 顶部查询-切换根据城市查找区 **/ $("#cityId").change(function() { var value = $(this).val(); $("#countyId").children().remove(); $("#countyId").append("<option value='0'>--请选择--</option>"); $("input[name^='father_"+value+"']").each(function(){ var val = $(this).val(); $("#countyId").append("<option value='"+val.split("_")[1]+"'>"+val.split("_")[0]+"</option>"); }); }); /** 顶部查询-切换根据区查找区域 **/ $("#countyId").change(function() { var value = $(this).val(); $("#blockId").children().remove(); $("#blockId").append("<option value='0'>--请选择--</option>"); $("input[name^='son_"+value+"']").each(function(){ var val = $(this).val(); $("#blockId").append("<option value='"+val.split("_")[1]+"'>"+val.split("_")[0]+"</option>"); }); }); });
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。