This article mainly introduces the replacement of the select drop-down box (Sample Code) for jquery implementation in provinces and cities. If you need it, you can refer to it and hope to help the implementation of the corresponding provinces and cities: <还有一些没封装起来>
Select a province to determine the city content.
Jsp code:
The Code is as follows:
Province -- Select -- Fujian Beijing Shandong Province Shanghai
Counties and cities -- Select --
Js Code:
The Code is as follows:
Function appendShi (shi) {// String concatenation, splicing Urban Area
Var fjs = '';
For (var I = 0; I {
Fjs + =' '+ Shi [I] +'';
}
Return fjs;
}
$ (Function (){
Var prince = ['fujian ', 'beijing', 'shandong', 'shanghai'];
Var fjs = ['xiamen ', 'quanzhou', 'fuzhou '];
Var bjs = ['beijing', 'chaoyang district ', 'haidian district', 'pinggu district '];
Var shs = ['huangpu district ', 'changning district', 'baoshan district ', 'jiading district'];
Var sds = ['jinan ', 'qingdao', 'yantai ', 'rizhao', 'laiwu ', 'ss'];
$ ("Select [name = 'prin']"). change (function (){
Var shi = $ ("# sel2"); // obtain the second select
Var prin = $ ("select [name = 'prin'] [select option: selected]"); // obtain the value of the selected identity
Var newShiSel = $ (' -- Select --');//
If (prin. val () = 'fujian '){
NewShiSel. append (appendShi (fjs ));
}
If (prin. val () = 'beijing '){
NewShiSel. append (appendShi (bjs ));
}
If (prin. val () = 'shanghai '){
NewShiSel. append (appendShi (shs ));
}
If (prin. val () = 'shandong '){
NewShiSel. append (appendShi (sds ));
}
Shi. replaceWith (newShiSel );
});
});