标签:
jsp代码
<script type="text/javascript"> $(function() { initProvinces(); }); /** * 获取省列表 */ function initProvinces() { $(‘#province‘).empty(); $.ajax({ type : "POST", url : basePath + "district/getProvinces.do", success : function(data) { $.each(data, function(i, it) { $("<option value=‘" + it.id + "‘ />" + it.name + "<br>").click(function() { initCities(it.id); }).appendTo($(‘#province‘)); }); } }); } /** * 获取市列表 */ function initCities(provinceID) { $(‘#city‘).empty(); $.ajax({ type : "POST", url : basePath + "district/getCities.do?province=" + provinceID, success : function(data) { $.each(data, function(i, it) { $("<option value=‘" + it.id + "‘ />" + it.name + "<br>").click(function() { initCounties(it.id); }).appendTo($(‘#province‘)); }); } }); } /** * 获取区县列表 */ function initCounties(cityID) { $(‘#county‘).empty(); $.ajax({ type : "POST", url : basePath + "district/getCounties.do?city=" + cityID, success : function(data) { $.each(data, function(i, it) { $("<option value=‘" + it.id + "‘ />" + it.name + "<br>") .appendTo($(‘#province‘)); }); } }); } //…… </script> <body> 选择地区: <select id=‘province‘><option>---省---</option></select> <select id=‘city‘><option>---市---</option></select> <select id=‘county‘><option>---区---</option></select> </body> spring MVC 代码: @Controller @RequestMapping(value = "/district") public class districtController { @Resource private DistrictService districtService; /** * 获取省列表 * @return * @throws Exception */ @RequestMapping(value = "getProvinces") @ResponseBody public Object getProvinces() throws Exception { return districtService.getProvinces(); } /** * 获取市列表 * @param province * @return * @throws Exception */ @RequestMapping(value = "getCities") @ResponseBody public Object getCities(@RequestParam(value = "province") String province) throws Exception { return districtService.getCities(); } // 再往下级的获取方式和getCities方法都相同,所以此处略过 }
标签:
原文地址:http://www.cnblogs.com/zhujiabin/p/4995591.html