jquery全国省市区三级联动插件distpicker

时间:2021-04-15 16:52:55

一、使用步骤:

1.引入js

<script src="distpicker/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="distpicker/distpicker.data.js" type="text/javascript" charset="utf-8"></script>
<script src="distpicker/distpicker.js" type="text/javascript" charset="utf-8"></script>

2.初始化

html部分

<!--地址三级联动-->
<div id="distpicker">
<div class="form-group">
  <select class="form-control" id="province10"></select>
</div>
<div class="form-group">
<select class="form-control" id="city10"></select>
</div>
<div class="form-group">
<select class="form-control" id="district10"></select>
</div>
</div>

js部分

$('#distpicker').distpicker({
autoSelect: false //是否自动选中项
});

3.完成效果

jquery全国省市区三级联动插件distpicker

二、vue项目使用

参考地址:https://distpicker.pigjian.com/

1.cmd

npm install v-distpicker --save

2.全局或局部引入:

方法一:全局引入
import VDistpicker from 'v-distpicker'
Vue.component('v-distpicker', VDistpicker) 方法二:局部引入
import VDistpicker from 'v-distpicker'
export default {
components: { VDistpicker }
}

3.使用<template>

  <v-distpicker :placeholders="placeholders" @selected='onSelected'></v-distpicker>
<template> <script>
import VDistpicker from 'v-distpicker' export default {
components: { VDistpicker },
data() {
return {
      address:{province: '',city:'',area:''},
placeholders: {
province: '------- 省 --------',
city: '--- 市 ---',
area: '--- 区 ---',
}
}
},
methods:{

    //选择省市区
    onSelected(data){
      this.address.province = data.province.value;
      this.address.city = data.city.value;
      this.address.area = data.area.value;
    },

  }
}
</script>