Blame view

assets/global/plugins/cityselect.js 2.61 KB
6eb38308   Andy   add
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
  /**
   * Created by atao on 2017/8/30.
   */
  var citySelect ={
      init:function(){
          var $prov = $("#prov");
          var $city = $("#city");
          var $dist = $("#dist");
          $prov.change(function () {
              var provId = $prov.val();
              citySelect.setCity(provId,$prov,$city,$dist);
          })
          $city.change(function () {
              var cityId=$city.val();
              citySelect.setDist(cityId,$prov,$city,$dist);
          })
          citySelect.setProv($prov,$city,$dist);
      },
      setProv:function($prov,$city,$dist){
          $prov.empty();
          var provArray = cityData.prov['0'];
          var html='';
          $.each(provArray,function (index,item) {
              if(0 == index){
                  html+="<option value='"+item.id+"' data-areacode='"+item.areaCode+"' data-parentid='"+item.parentId+"' selected>"+item.areaName+"</option>"
              }else{
                  html+="<option value='"+item.id+"' data-areacode='"+item.areaCode+"' data-parentid='"+item.parentId+"'>"+item.areaName+"</option>"
              }
          })
          $prov.append(html);
          $prov.selectpicker('refresh');
          //触发省份的change事件
          $prov.trigger('change');
      },
      setCity:function(provId,$prov,$city,$dist){
          $city.empty();
          provId +='';
          var cityArray = cityData.city[provId];
  
          var html='';
          $.each(cityArray,function (index,item) {
              if(0 == index){
                  html+="<option value='"+item.id+"' data-areacode='"+item.areaCode+"' data-parentid='"+item.parentId+"' selected>"+item.areaName+"</option>"
              }else{
                  html+="<option value='"+item.id+"' data-areacode='"+item.areaCode+"' data-parentid='"+item.parentId+"'>"+item.areaName+"</option>"
              }
          })
          $city.append(html);
          $city.selectpicker('refresh');
          //触发城市的change事件
          $city.trigger('change');
      },
      setDist:function (cityId,$prov,$city,$dist) {
          $dist.empty();
          cityId+='';
          var distArray = cityData.dist[cityId];
  
          var html='';
          $.each(distArray,function (index,item) {
              if(0 == index){
                  html+="<option value='"+item.id+"' data-areacode='"+item.areaCode+"' data-parentid='"+item.parentId+"' selected>"+item.areaName+"</option>"
              }else{
                  html+="<option value='"+item.id+"' data-areacode='"+item.areaCode+"' data-parentid='"+item.parentId+"'>"+item.areaName+"</option>"
              }
          })
          $dist.append(html);
          $dist.selectpicker('refresh');
          //触发区县的change事件
          $dist.trigger('change');
      }
  
  
  
  }