国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

chosen實現(xiàn)省市區(qū)三級聯(lián)動

2019-11-19 13:14:30
字體:
來源:轉載
供稿:網友

本文實例為大家分享了chosen實現(xiàn)省市區(qū)三級聯(lián)動的具體代碼,供大家參考,具體內容如下

效果圖:

一、資源

1.1、css資源

<link href="../../css/plugins/chosen/chosen.css" rel="stylesheet">

1.2、js資源

<script src="../../js/plugins/chosen/chosen.jquery.js"></script>

二、代碼

<div class="row">  <div class="form-group col-sm-2">  <div class="input-group">   <select data-placeholder="選擇省份..." id="province" class="province-chosen-select" tabindex="1">   <option value="">請選擇省份</option>   <#if provinceList?? && provinceList?size gt 0>   <#list provinceList as province>   <option value="${province.provinceId!}" >${province.name!}</option>  </#list>  </#if>  </select>  </div>  </div>  <div class="form-group col-sm-2" style="margin-left: 36px;">  <div class="input-group">  <select data-placeholder="選擇城市..." id="city" class="city-chosen-select" tabindex="2">  <option value="">請選擇城市</option>   </select>  </div> </div> <div class="form-group col-sm-2" style="margin-left: 36px;">  <div class="input-group">   <select data-placeholder="選擇區(qū)縣..." class="area-chosen-select" id="area" tabindex="3">   <option value="">請選擇區(qū)縣</option>  </select>  </div> </div></div>

三、javascript代碼

<script type="text/javascript"> $(function(){  $('.province-chosen-select').chosen({   disable_search_threshold: 10,   no_results_text: '沒有找到',//沒有搜索到匹配項時顯示的文字   width: '240px',   disable_search:false, // 設置為 true 隱藏單選框的搜索框   disable_search_threshold:0 //少于 n 項時隱藏搜索框  });  $('.city-chosen-select').chosen({   disable_search_threshold: 10,   no_results_text: '沒有找到',//沒有搜索到匹配項時顯示的文字   width: '240px',   disable_search:false, // 設置為 true 隱藏單選框的搜索框   disable_search_threshold:0 //少于 n 項時隱藏搜索框  });  $('.area-chosen-select').chosen({   disable_search_threshold: 10,   no_results_text: '沒有找到',//沒有搜索到匹配項時顯示的文字   width: '240px',   disable_search:false, // 設置為 true 隱藏單選框的搜索框   disable_search_threshold:0 //少于 n 項時隱藏搜索框  });   }) //Chosen 觸發(fā)標準的 change 事件,同時會傳遞 selected or deselected 參數(shù), 方便用戶獲取改變的選項 $('.province-chosen-select').on('change', function(e, params) {  findCitiesByProvince(e, params);  }); $('.city-chosen-select').on('change', function(e, params) {  findAreasByCity(e, params);  });  function findCitiesByProvince(e, params) {  var provinceId = params.selected;  $.post("/common/find_cities_by_province", {  "provinceId":provinceId  }, function(data){   $('#city option:first').nextAll().remove();   $('#area option:first').nextAll().remove();   var html = '';   for (var i = 0; i < data.length; i++) {   html+='<option value="'+data[i].cityId+'" hassubinfo="true">'+data[i].name+'</option>'   }   $("#city").append(html);   //通過 JS 改變 select 元素選項時應該觸發(fā)此事件,以更新 Chosen 生成的選框   $('.city-chosen-select').trigger('chosen:updated');   $('.area-chosen-select').trigger('chosen:updated');  }) } function findAreasByCity(e, params) {  var cityId = params.selected;  $.post("/common/find_areas_by_city", {  "cityId":cityId  }, function(data){   $('#area option:first').nextAll().remove();   var html = '';   for (var i = 0; i < data.length; i++) {   html+='<option value="'+data[i].areaId+'" hassubinfo="true">'+data[i].name+'</option>'   }   $("#area").append(html);   //通過 JS 改變 select 元素選項時應該觸發(fā)此事件,以更新 Chosen 生成的選框   $('.area-chosen-select').trigger('chosen:updated');  }) } function submitBtn() {  $("#result_div").html('');  var provinceId = $("#province").val();  var provinceName = $("#province option:selected").text();  var cityId = $("#city").val();  var cityName = $("#city option:selected").text();  var areaId = $("#area").val();  var areaName = $("#area option:selected").text();  $("#result_div").append("provinceId="+provinceId+"<br>")  .append("provinceName="+provinceName+"<br>")  .append("cityId="+cityId+"<br>")  .append("cityName="+cityName+"<br>")  .append("areaId="+areaId+"<br>")  .append("areaName="+areaName+"<br>"); } </script>

四、java代碼

 /** * * @Title: findCitiesByProvince * @Description: 根據(jù)省份獲取城市列表 * @author: 大都督 * @param provinceId * @return * @return: MessageInfo */ @RequestMapping("/find_cities_by_province") @ResponseBody public List<City> findCitiesByProvince(String provinceId) {  Assert.hasText(provinceId, StringText.provinceId_must);  return cityDao.findByProvinceId(provinceId); } /** * * @Title: findAreasByCity * @Description: 根據(jù)城市獲取區(qū)縣列表 * @author: 大都督 * @param cityId * @return * @return: List<City> */ @RequestMapping("/find_areas_by_city") @ResponseBody public List<Area> findAreasByCity(String cityId) {  Assert.hasText(cityId, StringText.cityId_must);  return areaDao.findByCity(cityId); }

 以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持武林網。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 丰都县| 新余市| 封开县| 武隆县| 环江| 吕梁市| 林芝县| 博爱县| 长武县| 柘城县| 黄陵县| 宁德市| 龙门县| 洪湖市| 嘉鱼县| 临沭县| 潞城市| 兴安盟| 邯郸市| 华坪县| 巴林右旗| 大英县| 磐安县| 德格县| 牙克石市| 巴里| 临朐县| 宜宾县| 蕲春县| 图们市| 渑池县| 慈利县| 苍山县| 左云县| 陇南市| 罗山县| 龙南县| 乐昌市| 浦县| 平远县| 长武县|