省、市二级级联下拉列表
<label>城市:</label> <select id="applicant_provinceCode" class="ui-select"> <option value="" selected>请选择</option> <c:forEach items="${provinceList}" var="province"> <option value="${province.cityCode}" <c:if test="${geFamilyCardMemberInfo.city == province.cityCode}">selecte d</c:if>>${province.cityName}</option> </c:forEach> </select> <select id="applicant_cityCode" class="ui-select" name="geFamilyCardMemberInfo.secondCity"> <option value="" selected>请选择</option> </select>
$("#applicant_provinceCode").change(function(){ var province = $("#applicant_provinceCode").val(); var testResultStr = '<option value="" selected>请选择</option>'; $.ajax({ type : 'post', url : contextRootPath+"/familyCard/getFamilyMemberSecondArea.do", data :{ "province":province, }, async : false, dataType :'json', success : function(data){ for(var i=0;i<data.length;i++){ if(secondCity==data[i].CITYCODE){ testResultStr += '<option value='+data[i].CITYCODE+'selected'+'>'+data[i].CITYNAME+'</option>'; }else{ } testResultStr += '<option value='+data[i].CITYCODE+'>'+data[i].CITYNAME+'</option>'; } $("#applicant_cityCode").html(testResultStr); }, error : function() { a_alert("系统异常,请稍后再试。"); } }) })
/** * 获取二级地区 * @return */ public void getFamilyMemberSecondArea(){ try { String regionCode = super.getRequest().getParameter("province"); List<Map<String, Object>> cityList = jdbcTemplate.queryForList("select lo.CITYCODE,lo.CITYNAME from GE_FAMILYCARD_CITY lo where lo.citylevel = '2' and lo.parentcode = '"+regionCode+"'"); //[{CITYCODE=120200, CITYNAME=县}, {CITYCODE=120100, CITYNAME=市辖区}] JSONArray object=JSONArray.fromObject(cityList); renderText(object.toString()); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }