(function(mod) { if (typeof exports == "object" && typeof module == "object") // CommonJS 瑙勮寖 module.exports = mod; else if (typeof define == "function" && define.amd) // AMD 瑙勮寖 return define(['jquery'], mod); else // Plain browser env 娴忚鍣 this.tools = mod; })(function() { var ui = {}; // 鐪佸競鍒囨崲 ui.province = { // template /* ------------------------------------------------------------- -------------------------------------------------------------*/ url_province: SITE_URL + 'province/province_ajax', url_province_city: SITE_URL + 'province/city_ajax', init: function(pv) { l = arguments[1] ? arguments[1] : 0; $.ajax({ url: this.url_province, type: 'GET', dataType: 'json' }) .done(function(data) { op = ''; $.each(data, function(index, el) { if (l && l.province == el.id) { op += ''; }); console.log(op); pv.append(op); }); _city = pv.next('.province_city'); if (l) { ui.province.get_city(l.province, _city, l.city); } else { ui.province.get_city(1, _city); } // 鐪侀€夋嫨杩涜澶勭悊 $(pv).on('change', function(event) { pid = $(this).val(); _province = $(this); _city = $(this).next('.province_city'); ui.province.get_city(pid, _city); }); }, // pid 鐪両D city涓篶ity select鐨勫璞 get_city: function(pid, city) { var lc = arguments[2] ? arguments[2] : 0; $.ajax({ url: this.url_province_city, type: 'GET', dataType: 'json', data: { pid: pid } }) .done(function(data) { op = ''; $.each(data, function(index, el) { if (lc && lc == el.id) { op += ''; }); city.html(''); city.append(op); }); } }; return ui; });