First look at the extension of JQ 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) {//two-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 is the function in PHP as follows ========
City Linkage Script
function Cityselect ($n =2, $s 1=province, $s 2=city, $s 3=area, $v 1=320000, $v 2=320500, $v 3=320501) {
$db = new Db_sql; Initializing the database
$db->connect (Db_database, Db_host, Db_user, Db_password); Database connection
$db->db_sql ("Set names GBK");
Linkage Ajax Script
$tmp = "";
Province selection
$tmp. = ""; $db->query (" select * from Sz_chinacity where right (Citypostcode, 4) = 0000 ORDER BY Cityid ASC "); while ($db->next_record ()) {if ($db->record[citypostcode]== $v 1) {$tmp. = "Record[citypostcode]. "Selected>". $db->record[cityname]. "; }else{$tmp. = "Record[citypostcode]. "" > ". $db->record[cityname]."; }} $tmp. = "";
City selection
$tmp. = ""; $cityid = substr ($v 1,0,2); $db->query (" select * from Sz_chinacity where right (Citypostcode, 2) = XX and Left (CITYPOSTC Ode, 2) = ". $cityid." And Right (Citypostcode, 4) <> 0000 ORDER BY Cityid ASC "); while ($db->next_record ()) {if ($db->record[citypostcode]== $v 2) {$tmp. = "Record[citypostcode]. "Selected>". $db->record[cityname]. "; }else{$tmp. = "Record[citypostcode]. "" > ". $db->record[cityname]."; }} $tmp. = "";
if ($n ==3) {
Region selection
$tmp. = ""; $cityid = substr ($v 2,0,4); $db->query (" select * from Sz_chinacity where left (Citypostcode, 4) = ". $cityid." And Right ( Citypostcode, 2) <> ORDER by Cityid ASC "); while ($db->next_record ()) {if ($db->record[citypostcode]== $v 3) {$tmp. = "Record[citypostcode]. "Selected>". $db->record[cityname]. "; }else{$tmp. = "Record[citypostcode]. "" > ". $db->record[cityname]."; }} $tmp. = "";
}
Echo $tmp;
}
When called:
http://www.bkjia.com/PHPjc/486524.html www.bkjia.com true http://www.bkjia.com/PHPjc/486524.html techarticle first look at the extension of JQ as follows://city selected JQuery.fn.cityselect = function (N,S1,S2,S3) {if (n!=3) (n!=2)) {n=2}; if (s1==) {S1=provi NCE}; if (s2==) {s2=city}; if (s3==) {s3=are ...