First, let's take a look at the JQ extension: // cityselectedjQuery. fn. cityselect = function (n, s1, s2, s3) {if (n! = 3) (n! = 2) {n = 2}; if (s1 =) {s1 = province}; if (s2 =) {s2 = city}; if (s3 =) {s3 =
The JQ extension is as follows:
// City selected
JQuery. fn. cityselect = function (n, s1, s2, s3 ){
If (n! = 3) & (n! = 2) {n = 2 };
If (s1 = "") {s1 = "province "};
If (s2 = "") {s2 = "city "};
If (s3 = "") {s3 = "area "};
If (n = 2) {// second-level linkage
// Alert (s1 + $ ("select [@ name = '" + s1 + "'] option [@ selected]"). val ());
$ ("Select [@ name = '" + s1 + "']"). bind ("change", function (event ){
$. Ajax ({
Type: "GET ",
Url: "/inc/lib/ajax_city.php ",
Data: "n = v2 & cityid =" + $ ("select [@ name = '" + s1 + "'] option [@ selected]"). val (),
Success: function (opt) {$ ("select [@ name = '" + s2 + "']"). empty (). append (opt );}
});
});
}
If (n = 3) {// Three-level linkage
$ ("Select [@ name = '" + s1 + "']"). bind ("change", function (event ){
$. Ajax ({
Type: "GET ",
Url: "/inc/lib/ajax_city.php ",
Data: "n = v2 & cityid =" + $ ("select [@ name = '" + s1 + "'] option [@ selected]"). val (),
Success: function (opt ){
$ ("Select [@ name = '" + s2 + "']"). empty (). append (opt );
$. Ajax ({
Type: "GET ",
Url: "/inc/lib/ajax_city.php ",
Data: "n = v3 & cityid =" + $ ("select [@ name = '" + s2 + "'] option [@ selected]"). val (),
Success: function (opt ){
$ ("Select [@ name = '" + s3 + "']"). empty (). append (opt );
}
});
}
});
});
$ ("Select [@ name = '" + s2 + "']"). bind ("change", function (event ){
$. Ajax ({
Type: "GET ",
Url: "/inc/lib/ajax_city.php ",
Data: "n = v3 & cityid =" + $ ("select [@ name = '" + s2 + "'] option [@ selected]"). val (),
Success: function (opt) {$ ("select [@ name = '" + s3 + "']"). empty (). append (opt );}
});
});
}
};
Next, the functions in PHP are as follows ========
// City linkage script
Function cityselect ($ n = 2, $ s1 = 'Vince ', $ s2 = 'city', $ s3 = 'region', $ v1 = '2016 ', $ v2 = '000000', $ v3 = '000000 '){
$ Db = new DB_ SQL; // initialize the database
$ Db-> connect (DB_Database, DB_Host, DB_User, DB_Password); // database connection
$ Db-> DB_ SQL ("set names gbk ");
// Link the AJAX script
$ Tmp ="