Provincial City Menu Linkage, AJAX 3-level menu Linkage _php Tutorial

Source: Internet
Author: User
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 ...

  • 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.