Province and city menu linkage, AJAX level 3 menu linkage_PHP tutorial

WBOY
Release: 2016-07-13 17:37:58
Original
775 people have browsed it

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){//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);}
});

});

}

};

The next function in PHP is as follows ========

//City linkage script
function cityselect($n=2,$s1=province,$s2=city,$s3=area,$v1=320000,$v2=320500,$v3=320501){
$db = new DB_Sql; //Initialize database
$db->connect(DB_Database, DB_Host, DB_User, DB_Password); //Database connection
$db->DB_Sql("set names gbk");
//Linked AJAX script
$tmp = " ";
//Province selection
$tmp .= " ";
//City selection
$tmp .= " ";


if ($n==3){
//Region selection
$tmp .= " ";
}
echo $tmp;
}

When calling:

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486524.htmlTechArticleFirst 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=are...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template