function getprov(){
var prov=$("#pro");
var str="";
ajax("tcentre.php",str,
function(data){
var obj = eval('('+data+')');
$("#pro").empty();
$("#pro").prepend("<option value='-1'>请选择市</option>");
for(var p in obj){
$("#pro").append("<option value="+obj[p].zonecode+">"+obj[p].zonename+"</option>");
}
}
);
}
function getcity(){
var a = $("#pro").val();
var str="code="+a;
ajax("tcentre1.php",str,
function(data){
var obj = eval('('+data+')');
$("#city").empty();
$("#city").prepend("<option value='-1'>请选择市</option>");
for(var p in obj){
$("#city").append("<option value="+obj[p].zonecode+">"+obj[p].zonename+"</option>");
}
}
);
}
function getq(){
var a = $("#city").val();
var str="code="+a;
ajax("tcentre2.php",str,
function(data){
var obj = eval('('+data+')');
$("#zone").empty();
$("#zone").prepend("<option value='-1'>请选择区</option>");
for(var p in obj){
$("#zone").append("<option value="+obj[p].zonecode+">"+obj[p].zonename+"</option>");
}
}
);
}
function gets(){
var a = $("#zone").val();
var str="code="+a;
ajax("tcentre3.php",str,
function(data){
var obj = eval('('+data+')');
$("#street").empty();
$("#street").prepend("<option value='-1'>请选择街道</option>");
for(var p in obj){
$("#street").append("<option value="+obj[p].zonecode+">"+obj[p].zonename+"</option>");
}
}
);
}
function ajax(url,poststr,success) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST",url);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlhttp.send(poststr);
xmlhttp.onreadystatechange = function () {
if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
success(xmlhttp.responseText);
}
}
}
body οnlοad=”getprov()”
select name=”province” id=”pro” οnchange=”getcity()”
option 请选择省 option
select
select name=”city” id=”city” οnchange=”getq()”
option 请选择市 option
select
select name=”zone” id=”zone” οnchange=”gets()”
option请选择区/option
select
select name=”street” id=”street”
option 请选择街道 option
select
body
include 'db.php';
$db = new DB();
$sql = "select * from diqudaima where areaid=1";
$res=$db->get($sql);
$arr = array();
for($i=1;$i<count($res);$i++){
$arr[$i-1]['province'] = $res[$i-1][1];
$arr[$i-1]['city'] = $res[$i-1][2];
$arr[$i-1]['zonename'] = $res[$i-1][5];
$arr[$i-1]['zonecode'] = $res[$i-1][4];
}
$a = json_encode($arr);
echo $a;
include 'db.php';
$db = new DB();
$code = $_POST['code'];
$sql = "select * from diqudaima where areaid='2' and zonecode like '$code%'";
$res=$db->get($sql);
$arr =array();
for($i=1;$i<count($res);$i++){
$arr[$i-1]['province'] = $res[$i-1][1];
$arr[$i-1]['city'] = $res[$i-1][2];
$arr[$i-1]['zonename'] = $res[$i-1][5];
$arr[$i-1]['zonecode'] = $res[$i-1][4];
}
$a = json_encode($arr);
echo $a;
include 'db.php';
$db = new DB();
$code = $_POST['code'];
$sql = "select * from diqudaima where areaid='3' and zonecode like '$code%'";
$res=$db->get($sql);
$arr =array();
for($i=1;$i<count($res);$i++){
$arr[$i-1]['province'] = $res[$i-1][1];
$arr[$i-1]['city'] = $res[$i-1][2];
$arr[$i-1]['zonename'] = $res[$i-1][5];
$arr[$i-1]['zonecode'] = $res[$i-1][4];
}
$a = json_encode($arr);
echo $a;
include 'db.php';
$db = new DB();
$code = $_POST['code'];
$sql = "select * from diqudaima where areaid='4' and zonecode like '$code%'";
$res=$db->get($sql);
$arr =array();
for($i=1;$i<count($res);$i++){
$arr[$i-1]['province'] = $res[$i-1][1];
$arr[$i-1]['city'] = $res[$i-1][2];
$arr[$i-1]['zonename'] = $res[$i-1][5];
$arr[$i-1]['zonecode'] = $res[$i-1][4];
}
$a = json_encode($arr);
echo $a;