In the daily Internet, we often encounter the provincial urban choice, here we explain the "provincial urban Three linkage"
First: Write div tags in HTML pages
<title> three-level linkage </title><script src= "jquery-2.0.0.min.js" ></script><script src= "Sanji.js" ></script>
Second: code that runs in JScript
1. First, the drop-down list fills the event
$ (document). Ready (function (e) { $ ("#sanji"). HTML ("<select id= ' sheng ' ></select><select id= ' shi ' ></select><select id= ' qu ' ></select> ');//fill content//1. Fill province Fillsheng ();//2. Fill City Fillshi ();//3. Filling area fillqu ();
2. If the first level of the provincial selection changes, the second and third levels will also change
If the province is selected to change, go to fill the city and the district $ ("#sheng"). Change (function () {//Changed city Fillshi ();//Changed area Fillqu ();})
3. If the second level of the city selection changes, the third level will change
If the city chooses to change, go to fill the area $ ("#shi"). Change (function () {//Alter area fillqu ();})
4. The Province fill Fillsheng () function referenced above
Fill Province method function Fillsheng () {//Find parent code var pcode= "0001";//Call Ajax$.ajax ({async:false,url: "chuli.php", Data:{pcode: Pcode},type: "POST", DataType: "TEXT", success:function (data) {var str= ""; var hang = Data.split ("|"); for (Var i=0;i
5. The City fill Fillshi () function referenced above
Fill the city method function Fillshi () {//Find the parent codenamed Var pcode=$ ("#sheng"). Val ();//Call Ajax$.ajax ({async:false,url: "chuli.php", Data: {pcode:pcode},type: "POST", DataType: "TEXT", success:function (data) {var str= ""; var hang = Data.split ("|"); for (Var i=0;i
6. The area filled fillqu () function referenced above
The Fill Area method function Fillqu () {//finds the parent codenamed Var pcode=$ ("#shi"). Val ();//Call Ajax$.ajax ({async:false,url: "chuli.php", data:{ Pcode:pcode},type: "POST", DataType: "TEXT", success:function (data) {var str= ""; var hang = Data.split ("|"); for (Var i=0;i
Third: Ajax-run chuli.php code in JScript
<?php$pcode=$_post["Pcode"];include ("DBDA.class.php"), $db =new Dbda (); $sql = "Select Areacode,areaname, Parentareacode from Chinastates where parentareacode= ' {$pcode} ' "; Echo $db->strquery ($sql);
Three-level linkage between provincial and urban areas