欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2018年08月16日 16:17:16   作者:我是大都督  
這篇文章主要為大家詳細 介紹了chosen實現(xiàn)省市區(qū)三級聯(lián)動,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了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);
 }

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

相關文章

最新評論