$(function(){
$ ("# province"). CityCascade ("# city ")。 CityCascade ('select',' Henan Province');
//or
$ ("# province"). CityCascade ("# city ")。 CityCascade ('select',' Henan',' Kaifeng');
}
/**
*? java? Dikiye
*? Copy city data from the internet.
*? The cascading function is also a good idea on the reference network.
*? For future convenience, it is packaged as a plug-in.
*? Supplement? Add the selected city method selection.
*/
(Function ($) {
$.fn.cityCasCade? =? Function (operation, province, city) {
var? selectCity=null,params=null,overparams = null
if(typeof? Operation? ==? "String") (
If (operation? ==? "Select") {
If (province) {
$ (this). Find ("Options"). each(function(){
If ($ (this). Val()= = province)
this.selected = true
$ (this). change();
If (city) {
$($ . fn . city cascade param . select city)。 Find ("Options"). each(function(){
If ($ (this). val()==city){
this.selected = true
$ (this). change();
}
});
}
}
});
}
Return? $ (this);
}
selectCity = operation
}
Otherwise {
if(operation . selector)select city = operation . selector;
if(operation . overide & amp; & ampoperation.data) super program = operation.data.
Or what? params = operation.data
}
$.fn.cityCascadeParam? ={};
$.fn.cityCascadeParam.data? =? _ province _;
$ . fn . city cascade param . select city? =? null
What if (choose a city)? $ . fn . city cascade param . select city = select city;
Or what? Throw? "City Selector cannot be empty";
$ . fn . city cascade param . city value =? $($ . fn . city cascade param . select city+":first ")。 val();
$ . fn . city cascade param . city text =? $($ . fn . city cascade param . select city+":first ")。 text();
if(over rams)$ . fn . city cascade param . data = over rams;
Or what? $.extend($ . fn . city cascade param . data,? params);
$ . fn . city cascade param . load province? =? Function (self)
for(var? p? Are you online? $. fn . city cascade param . data){
var? opt = document . createelement(" option ");
opt . innerhtml = p;
opt . value = p;
self . appendchild(opt);
}
}
$.fn.cityCascadeParam.loadCity? =? Function (Parent) {
var? Self? =? $($ . fn . city cascade param . select city)。 get(0);
If (! Self) Throw? "City drop-down box not found? City selector? & gt>? +? $ . fn . city cascade param . select city;
var? selectProvince=$(parent)。 val();
If (select province? Are you online? $. fn . city cascade param . data){
var? city s = $ . fn . city cascade param . data[select province];
self.innerHTML =
for(var? Index = 0; Index & lt city length; index++){
opt = document . createelement(" option ");
opt . innerhtml = citys[index];
opt . value = citys[index];
self . appendchild(opt);
}
} Otherwise {
self.innerHTML =
opt = document . createelement(" option ");
opt . innerhtml = $ . fn . city cascade param . city text;
opt . value = $ . fn . city cascade param . city value;
self . appendchild(opt);
}
}
this.each(function(){
$ . fn . city cascade param . load province(this);
$ (this). change(function(){
$ . fn . city cascade param . load city(this);
});
});
Return? $ (this);
}
})($);
var? _provinces_={ Sichuan Province: ["Chengdu", "Zigong", "Panzhihua", "Luzhou", "Deyang", "Mianyang", "Guangyuan", "Suining", "Neijiang", "Leshan", "Nanchong" and "Meishan", Liangshan Yi Autonomous Prefecture], Shanxi Province: [Taiyuan, Datong, Yangquan, Changzhi, Jincheng, Shuozhou, Jinzhong, Yuncheng, Xinzhou, Linfen and Lvliang], Inner Mongolia: [Wulanchabu City]. Jinzhou, Yingkou, Fuxin, Tonghua, baishan city and Songyuan Jiangsu Province: [Nanjing, Wuxi, Xuzhou, Changzhou, Suzhou, Nantong, Lianyungang, Huai 'an, Yancheng, etc. "Lishui City"], Anhui Province: ["Hefei City", "Wuhu City", "Bengbu City", "Huainan City", "Maanshan City", "Huaibei City", "Tongling City", "Anqing City", "Huangshan City", "Chuzhou City", "Fuyang City", "Suzhou City", Weifang City, Jining City, Tai 'an City, Weihai City, Rizhao City, Laiwu City, Linyi City, Dezhou City, Liaocheng City, Binzhou City and Heze City], Henan Province: [Zhengzhou City, Kaifeng City and Heze City] Xiangxi Tujia and Miao Autonomous Prefecture], Guangdong Province: [Guangzhou, Shaoguan, Meizhou, Shanwei, Heyuan, Yangjiang, Qingyuan, Dongguan, Zhongshan, Chaozhou, Jieyang and Yunfu] Chongqing: [Chongqing]], Guizhou: [Guiyang, Liupanshui, Zunyi, Anshun, Tongren, Southwest Buyi and Miao Autonomous Prefecture, Bijie Xishuangbanna Dai Autonomous Prefecture, Dali Bai Autonomous Prefecture, Dehong Autonomous Prefecture and Nujiang Lisu Autonomous Prefecture. Shaanxi Province: [“Xi 'an, Tongchuan, Baoji, Xianyang, Weinan, Yan 'an, Hanzhong, Yulin, Ankang, Jiuquan, Qingyang, Dingxi, Longnan, Linxia Hui Autonomous Prefecture, Xinjiang Autonomous Region: ["Urumqi", "Karamay", "Turpan", "Hami", "Changji Hui Autonomous Prefecture", "Bortala Mongolian Autonomous Prefecture", "Bayinguoleng Mongolian Autonomous Prefecture", "Aksu Region" and "Kizilsu Kirgiz Autonomous Prefecture]. "Altay Region"], Taiwan Province Province: ["Taipei City"], Hong Kong SAR: ["Hong Kong"], Macao SAR: ["Macau"], Hebei Province: ["Shijiazhuang", "Tangshan", "Qinhuangdao", "Zhangjiakou", "Chengde", "Langfang", "Handan",