测试地址:http://www.mlmm.cn/mypage/?name=ceshi
测试页代码:
复制代码 代码如下:
regionss函数代码:
QUOTE:
复制代码 代码如下://省市地3级联动下拉菜单函数regionss省.市.地
functionregionss($country="中华人民共和国")
{
global$db;$i=1;
$text="<selectid="select1"name="select1"onchange="startRequest()"style="width:90px;">
$result=$db->query("SELECTprovinceFROM".TABLE_PROVINCE."WHEREcountry='$country'ORDERBYprovinceid");
while($r=$db->fetch_array($result))
{
$text.="
$i++;
}
$text.="select>";
$text.=" <selectid="select2"name="select2"onchange="startRequesta()"style="width:90px;">
$text.="<selectid="select3"name="select3"style="width:90px;">
return$text;
}
regions.js的代码:
复制代码 代码如下://varab=newArray();
varxmlHttp;
varxmlHttpa;
functioncreateXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttp=newActiveXObject("Microsoft.XMLHTTP");
}
elseif(window.XMLHttpRequest){
xmlHttp=newXMLHttpRequest();
}
}
functioncreateXMLHttpRequesta(){
if(window.ActiveXObject){
xmlHttpa=newActiveXObject("Microsoft.XMLHTTP");
}
elseif(window.XMLHttpRequest){
xmlHttpa=newXMLHttpRequest();
}
}
functionstartRequest(){
createXMLHttpRequest();
createXMLHttpRequesta();
xmlHttp.onreadystatechange=handleStateChange;
xmlHttpa.onreadystatechange=handleStateChangearea;
document.getElementById('select2').options.length=0;
document.getElementById('select3').options.length=0;
varurl=document.form1.select1.value;
varqurl="/regions.php?province="+url+"&time="+newDate().getTime();
xmlHttp.open("GET",qurl,true);
xmlHttp.send(null);
//setTimeout("startRequest()",2000);
}
functionhandleStateChange(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
varobj=document.getElementById('select2');//将服务器返回的字符串写到页面中ID为select2的区域
obja=document.getElementById('select3');//将服务器返回的字符串写到页面中ID为select3的区域
eval(xmlHttp.responseText);
}
}
}
functionhandleStateChangearea(){
eval(xmlHttpa.responseText);
}
//varab=newArray();
functionstartRequesta(){
createXMLHttpRequesta();
xmlHttpa.onreadystatechange=handleStateChangea;
document.getElementById('select3').options.length=0;
varurl=document.form1.select2.value;
varqurl="/regions.php?city="+url+"&time="+newDate().getTime();
xmlHttpa.open("GET",qurl,true);
xmlHttpa.send(null);
//setTimeout("startRequest()",2000);
}
functionhandleStateChangea(){
if(xmlHttpa.readyState==4){
if(xmlHttpa.status==200){
varobja=document.getElementById('select3');
eval(xmlHttpa.responseText);
//将服务器返回的字符串写到页面中ID为select3的区域
}
}
}
数据岛regions.php页面代码
复制代码 代码如下:require"common.php";
$city=$city?$city:"";
$area=$area?$area:"";
if($province&&$city==''){
global$db;$i=1;
$result=$db->query("SELECTDISTINCTcityFROM".TABLE_CITY."WHEREprovince='$province'ORDERBYcityid");
while($r=$db->fetch_array($result))
{
$r[city]=iconv('gb2312','UTF-8',$r[city]);
echo"obj.options[obj.options.length]=newOption('".$r[city]."','".$r[city]."');n";
$i++;
}
$resultarea=$db->query("SELECTDISTINCTcityFROM".TABLE_CITY."WHEREprovince='$province'ORDERBYcityid");
$r=$db->fetch_array($resultarea);
$city=$r[city];
$resulta=$db->query("SELECTDISTINCTareaFROM".TABLE_CITY."WHEREcity='$city'ORDERBYcityid");
while($ra=$db->fetch_array($resulta))
{
$ra[area]=iconv('gb2312','UTF-8',$ra[area]);
echo"obja.options[obja.options.length]=newOption('".$ra[area]."','".$ra[area]."');n";
$i++;
}
}
if($city&&$province==''){
global$db;$i=1;
$result=$db->query("SELECTDISTINCTareaFROM".TABLE_CITY."WHEREcity='$city'ORDERBYcityid");
while($r=$db->fetch_array($result))
{
$r[area]=iconv('gb2312','UTF-8',$r[area]);
echo"obja.options[obja.options.length]=newOption('".$r[area]."','".$r[area]."');n";
$i++;
}
}
?>
地址信息数据库:
采用的是phpcms3.0里自带的数据库,我没有进行任何改动
本程序可以在phpcms3.0里直接使用,若在其他地方使用请自己修改