Jquery replaces the provincial/municipal select drop-down boxes (sample code) _ jquery

Source: Internet
Author: User
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 );
});
});

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.