省份城市菜单联动,AJAX 3级菜单联动
首先看JQ的扩展如下:
//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){//二级联动
//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){//三级联动
$("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);}
});
});
}
};
接下来是PHP里的函数如下========
//城市联动脚本
function cityselect($n=2,$s1=province,$s2=city,$s3=area,$v1=320000,$v2=320500,$v3=320501){
$db = new DB_Sql; //初始化数据库
$db->connect(DB_Database, DB_Host, DB_User, DB_Password); //数据库连接
$db->DB_Sql("set names gbk");
//联动AJAX脚本
$tmp = "
";
//省份选择
$tmp .= "
";
//城市选择
$tmp .= "
";
if ($n==3){
//地区选择
$tmp .= "
";
}
echo $tmp;
}
调用的时候:

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Journey through the vastness and set foot on the journey to the west! Today, Zhengtu IP officially announced that it will launch a cross-border cooperation with CCTV animation "Journey to the West" to jointly create a cultural feast that combines tradition and innovation! This cooperation not only marks the in-depth cooperation between the two major domestic classic brands, but also demonstrates the unremitting efforts and persistence of the Zhengtu series on the road of promoting Chinese traditional culture. Since its birth, the Zhengtu series has been loved by players for its profound cultural heritage and diversified gameplay. In terms of cultural inheritance, the Zhengtu series has always maintained respect and love for traditional Chinese culture, and skillfully integrated traditional cultural elements into the game, bringing more fun and inspiration to players. The CCTV animation "Journey to the West" is a classic that has accompanied the growth of generations.

To extend PHP function functionality, you can use extensions and third-party modules. Extensions provide additional functions and classes that can be installed and enabled through the pecl package manager. Third-party modules provide specific functionality and can be installed through the Composer package manager. Practical examples include using extensions to parse complex JSON data and using modules to validate data.

Title: Methods and code examples to resolve 403 errors in jQuery AJAX requests. The 403 error refers to a request that the server prohibits access to a resource. This error usually occurs because the request lacks permissions or is rejected by the server. When making jQueryAJAX requests, you sometimes encounter this situation. This article will introduce how to solve this problem and provide code examples. Solution: Check permissions: First ensure that the requested URL address is correct and verify that you have sufficient permissions to access the resource.

jQuery is a popular JavaScript library used to simplify client-side development. AJAX is a technology that sends asynchronous requests and interacts with the server without reloading the entire web page. However, when using jQuery to make AJAX requests, you sometimes encounter 403 errors. 403 errors are usually server-denied access errors, possibly due to security policy or permission issues. In this article, we will discuss how to resolve jQueryAJAX request encountering 403 error

There are many treasure chests in Mingchao Jinzhou City. Many players want to know where the treasure chests are. The editor has marked the locations of all the treasure chests. Players can just follow the marked numbers to find them one by one. Let’s take a look at this Mingchao article for details. The latest collection of all treasure chests in Jinzhou City. Mingchao Strategy Collection Mingchao Jinzhou City Treasure Box Collection Location 1: Jinzhou City (1-25) Twenty-five treasure boxes, five voice boxes Location 2: Jinzhou City (26-41) Fifteen treasure boxes, three A voice box, two flying hunters

NetEase's "Onmyoji" mobile game announced today that the Onmyoji x Hatsune Miku limited collaboration will officially begin on March 6. The collaboration-limited SSR Hatsune Miku (CV: Saki Fujita) and SSR Kagamine Rin (CV: Asami Shimoda) are coming to Heian Kyo! The linkage online special performance event will officially start in the game on March 9~

Using Ajax to obtain variables from PHP methods is a common scenario in web development. Through Ajax, the page can be dynamically obtained without refreshing the data. In this article, we will introduce how to use Ajax to get variables from PHP methods, and provide specific code examples. First, we need to write a PHP file to handle the Ajax request and return the required variables. Here is sample code for a simple PHP file getData.php:

How to solve the problem of jQueryAJAX error 403? When developing web applications, jQuery is often used to send asynchronous requests. However, sometimes you may encounter error code 403 when using jQueryAJAX, indicating that access is forbidden by the server. This is usually caused by server-side security settings, but there are ways to work around it. This article will introduce how to solve the problem of jQueryAJAX error 403 and provide specific code examples. 1. to make
