ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
### 省市区插件使用 **位置:** Public/plug/address/jquery_citys.js 插件文件 Public/plug/address/list.json 数据源json **插件地址:** https://github.com/mumuy/widget **参数:** three_city , province , city , area **新增时候调用:** <script src="__PUBLIC__/plug/address/jquery_citys.js"></script> <script> $('#three_city').citys({}) </script> **完整代码:** ~~~ <div class="form-group" id="three_city"> <label class="col-sm-2 control-label" style="width:12.5%">省份:</label> <div class="col-sm-3"> <select class="form-control" name="province"> </select> </div> <div class="col-sm-3"> <select class="form-control" name="city"> </select> </div> <div class="col-sm-3"> <select class="form-control" name="area"></select> </div> </div> ~~~ **截图:** ![](https://box.kancloud.cn/94065a43af5ab2fc01c15533ae4e046a_591x57.png) **编辑时候调用:** 在页面编辑的时候调用老的数据,进行默认的赋值,赋值所在区的代码就可以了 ~~~ <!-- 省市区调用判断是否有数据 --> <script type="text/javascript"> <if condition="$result['customer_area'] neq '' "> // 赋值省市区 $('#three_address').citys({code:{$result['customer_area']}}); <else /> // 初始化省市区 $('#three_address').citys({ required:false, nodata:'disabled', onChange:function(data){ var text = data['direct']?'(直辖市)':''; $('#place').text('当前选中地区:'+data['province']+text+' '+data['city']+' '+data['area']); } }); </if> </script> ~~~ **直辖市与省市区不同的Bug解决方案** ~~~ // 解决直辖市的二级没有三级的问题 if (empty($params['area'])) { $params['customer_city'] = $params['province']; // 市 $params['customer_area'] = $params['city']; // 区 } else { $params['customer_city'] = $params['city']; // 市 $params['customer_area'] = $params['area']; // 区 } ~~~