jquery realizes the city and province select Drop-down box replacement (sample code) _jquery

Source: Internet
Author: User

The corresponding implementation of provinces and cities:< still some not packaged up >

More selective provinces to determine the content of the city

JSP Code:

Copy Code code as follows:

<body>
Province <select name= "Prin" >
<option>--Please select--</option>
<option> Fujian </option>
<option> Beijing </option>
<option> Shandong </option>
<option> Shanghai </option>
</select>
County, city <select id= "Sel2" >
<option>--Please select--</option>
</select>
</body>

JS Code:
Copy Code code as follows:

function Appendshi (shi) {//string concatenation, stitching downtown
var fjs= ';
for (Var i=0;i<shi.length;i++)
{
Fjs + = ' <option> ' + shi[i]+ ' </option> ';
}
return FJS;
}
$ (function () {
var Prince = [' Fujian ', ' Beijing ', ' Shandong ', ' Shanghai '];
var fjs = [' Xiamen ', ' Quanzhou ', ' Fuzhou '];
var bjs = [' Beijing ', ' Chaoyang District ', ' Haidian ', ' Pinggu District '];
var SHS = [' Huangpu ', ' Changning district ', ' Baoshan ', ' Jiading '];
var SDS = [' Jinan ', ' Qingdao ', ' Yantai ', ' Rizhao ', ' Laiwu ', ' SSS '];

$ ("Select[name= ' Prin ']"). Change (function () {
var Shi = $ ("#sel2");//Get a second Select
var prin = $ ("select[name= ' Prin '][select option:selected]")//The value of the selected identity
var Newshisel = $ (' <select id= ' sel2 ' ><option>--Please select--</option></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.