无为清净楼资源网 Design By www.qnjia.com
绝对原创
测试地址: http://www.mlmm.cn/mypage/?name=ceshi
测试页代码:
复制代码 代码如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>php+ajax动态生成下拉菜单</title>
<script language="JavaScript" src="/UploadFiles/2021-04-02/regions.js"></head>
<body>
<form name="form1" method="post" action="">
<tr><td>{$regionss(中华人民共和国)}</td></tr>
</form>
</body>
</html>
regionss 函数代码:
QUOTE:
复制代码 代码如下://省市地3级联动下拉菜单函数 regionss 省.市.地
function regionss($country="中华人民共和国")
{
global $db; $i = 1;
$text="<select id=\"select1\" name=\"select1\" onchange=\"startRequest()\" style=\"width:90px;\"><option value=\"\">省/市/自治区</option>\n";
$result = $db->query("SELECT province FROM ".TABLE_PROVINCE." WHERE country='$country' ORDER BY provinceid");
while($r = $db->fetch_array($result))
{
$text .= "<option value=".$r['province'].">".$r['province']."</option> ";
$i++;
}
$text.="</select>";
$text.=" <select id=\"select2\" name=\"select2\" onchange=\"startRequesta()\" style=\"width:90px;\"><option value=\"\">市/县/区</option></select>\n";
$text.="<select id=\"select3\" name=\"select3\" style=\"width:90px;\"><option value=\"\">县级市/县</option></select>\n";
return $text;
}
regions.js 的代码:
复制代码 代码如下://var ab = new Array();
var xmlHttp;
var xmlHttpa;
function createXMLHttpRequest() {
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}
function createXMLHttpRequesta() {
if (window.ActiveXObject) {
xmlHttpa = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
xmlHttpa = new XMLHttpRequest();
}
}
function startRequest() {
createXMLHttpRequest();
createXMLHttpRequesta();
xmlHttp.onreadystatechange = handleStateChange;
xmlHttpa.onreadystatechange = handleStateChangearea;
document.getElementById('select2').options.length = 0;
document.getElementById('select3').options.length = 0;
var url = document.form1.select1.value;
var qurl = "/regions.php?province="+url+"&time="+new Date().getTime();
xmlHttp.open("GET", qurl, true);
xmlHttp.send(null);
//setTimeout("startRequest()",2000);
}
function handleStateChange() {
if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
var obj = document.getElementById('select2'); //将服务器返回的字符串写到页面中ID为select2的区域
obja = document.getElementById('select3'); //将服务器返回的字符串写到页面中ID为select3的区域
eval(xmlHttp.responseText);
}
}
}
function handleStateChangearea() {
eval(xmlHttpa.responseText);
}
//var ab = new Array();
function startRequesta() {
createXMLHttpRequesta();
xmlHttpa.onreadystatechange = handleStateChangea;
document.getElementById('select3').options.length = 0;
var url = document.form1.select2.value;
var qurl = "/regions.php?city="+url+"&time="+new Date().getTime();
xmlHttpa.open("GET", qurl, true);
xmlHttpa.send(null);
//setTimeout("startRequest()",2000);
}
function handleStateChangea() {
if(xmlHttpa.readyState == 4) {
if(xmlHttpa.status == 200) {
var obja = document.getElementById('select3');
eval(xmlHttpa.responseText);
//将服务器返回的字符串写到页面中ID为select3的区域
}
}
}
数据岛 regions.php 页面代码
复制代码 代码如下:<?php
require "common.php";
$city = $city ? $city : "";
$area = $area ? $area : "";
if($province && $city==''){
global $db; $i = 1;
$result = $db->query("SELECT DISTINCT city FROM ".TABLE_CITY." WHERE province='$province' ORDER BY cityid");
while($r = $db->fetch_array($result))
{
$r[city]=iconv('gb2312','UTF-8',$r[city]);
echo "obj.options[obj.options.length] = new Option('".$r[city]."','".$r[city]."');\n";
$i++;
}
$resultarea = $db->query("SELECT DISTINCT city FROM ".TABLE_CITY." WHERE province='$province' ORDER BY cityid");
$r = $db->fetch_array($resultarea);
$city = $r[city];
$resulta = $db->query("SELECT DISTINCT area FROM ".TABLE_CITY." WHERE city='$city' ORDER BY cityid");
while($ra = $db->fetch_array($resulta))
{
$ra[area]=iconv('gb2312','UTF-8',$ra[area]);
echo "obja.options[obja.options.length] = new Option('".$ra[area]."','".$ra[area]."');\n";
$i++;
}
}
if($city && $province==''){
global $db; $i = 1;
$result = $db->query("SELECT DISTINCT area FROM ".TABLE_CITY." WHERE city='$city' ORDER BY cityid");
while($r = $db->fetch_array($result))
{
$r[area]=iconv('gb2312','UTF-8',$r[area]);
echo "obja.options[obja.options.length] = new Option('".$r[area]."','".$r[area]."');\n";
$i++;
}
}
?>
地址信息数据库:
采用的是phpcms3.0里自带的数据库,我没有进行任何改动
本程序可以在phpcms3.0里直接使用,若在其他地方使用请自己修改
测试地址: http://www.mlmm.cn/mypage/?name=ceshi
测试页代码:
复制代码 代码如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>php+ajax动态生成下拉菜单</title>
<script language="JavaScript" src="/UploadFiles/2021-04-02/regions.js"></head>
<body>
<form name="form1" method="post" action="">
<tr><td>{$regionss(中华人民共和国)}</td></tr>
</form>
</body>
</html>
regionss 函数代码:
QUOTE:
复制代码 代码如下://省市地3级联动下拉菜单函数 regionss 省.市.地
function regionss($country="中华人民共和国")
{
global $db; $i = 1;
$text="<select id=\"select1\" name=\"select1\" onchange=\"startRequest()\" style=\"width:90px;\"><option value=\"\">省/市/自治区</option>\n";
$result = $db->query("SELECT province FROM ".TABLE_PROVINCE." WHERE country='$country' ORDER BY provinceid");
while($r = $db->fetch_array($result))
{
$text .= "<option value=".$r['province'].">".$r['province']."</option> ";
$i++;
}
$text.="</select>";
$text.=" <select id=\"select2\" name=\"select2\" onchange=\"startRequesta()\" style=\"width:90px;\"><option value=\"\">市/县/区</option></select>\n";
$text.="<select id=\"select3\" name=\"select3\" style=\"width:90px;\"><option value=\"\">县级市/县</option></select>\n";
return $text;
}
regions.js 的代码:
复制代码 代码如下://var ab = new Array();
var xmlHttp;
var xmlHttpa;
function createXMLHttpRequest() {
if (window.ActiveXObject) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}
function createXMLHttpRequesta() {
if (window.ActiveXObject) {
xmlHttpa = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
xmlHttpa = new XMLHttpRequest();
}
}
function startRequest() {
createXMLHttpRequest();
createXMLHttpRequesta();
xmlHttp.onreadystatechange = handleStateChange;
xmlHttpa.onreadystatechange = handleStateChangearea;
document.getElementById('select2').options.length = 0;
document.getElementById('select3').options.length = 0;
var url = document.form1.select1.value;
var qurl = "/regions.php?province="+url+"&time="+new Date().getTime();
xmlHttp.open("GET", qurl, true);
xmlHttp.send(null);
//setTimeout("startRequest()",2000);
}
function handleStateChange() {
if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
var obj = document.getElementById('select2'); //将服务器返回的字符串写到页面中ID为select2的区域
obja = document.getElementById('select3'); //将服务器返回的字符串写到页面中ID为select3的区域
eval(xmlHttp.responseText);
}
}
}
function handleStateChangearea() {
eval(xmlHttpa.responseText);
}
//var ab = new Array();
function startRequesta() {
createXMLHttpRequesta();
xmlHttpa.onreadystatechange = handleStateChangea;
document.getElementById('select3').options.length = 0;
var url = document.form1.select2.value;
var qurl = "/regions.php?city="+url+"&time="+new Date().getTime();
xmlHttpa.open("GET", qurl, true);
xmlHttpa.send(null);
//setTimeout("startRequest()",2000);
}
function handleStateChangea() {
if(xmlHttpa.readyState == 4) {
if(xmlHttpa.status == 200) {
var obja = document.getElementById('select3');
eval(xmlHttpa.responseText);
//将服务器返回的字符串写到页面中ID为select3的区域
}
}
}
数据岛 regions.php 页面代码
复制代码 代码如下:<?php
require "common.php";
$city = $city ? $city : "";
$area = $area ? $area : "";
if($province && $city==''){
global $db; $i = 1;
$result = $db->query("SELECT DISTINCT city FROM ".TABLE_CITY." WHERE province='$province' ORDER BY cityid");
while($r = $db->fetch_array($result))
{
$r[city]=iconv('gb2312','UTF-8',$r[city]);
echo "obj.options[obj.options.length] = new Option('".$r[city]."','".$r[city]."');\n";
$i++;
}
$resultarea = $db->query("SELECT DISTINCT city FROM ".TABLE_CITY." WHERE province='$province' ORDER BY cityid");
$r = $db->fetch_array($resultarea);
$city = $r[city];
$resulta = $db->query("SELECT DISTINCT area FROM ".TABLE_CITY." WHERE city='$city' ORDER BY cityid");
while($ra = $db->fetch_array($resulta))
{
$ra[area]=iconv('gb2312','UTF-8',$ra[area]);
echo "obja.options[obja.options.length] = new Option('".$ra[area]."','".$ra[area]."');\n";
$i++;
}
}
if($city && $province==''){
global $db; $i = 1;
$result = $db->query("SELECT DISTINCT area FROM ".TABLE_CITY." WHERE city='$city' ORDER BY cityid");
while($r = $db->fetch_array($result))
{
$r[area]=iconv('gb2312','UTF-8',$r[area]);
echo "obja.options[obja.options.length] = new Option('".$r[area]."','".$r[area]."');\n";
$i++;
}
}
?>
地址信息数据库:
采用的是phpcms3.0里自带的数据库,我没有进行任何改动
本程序可以在phpcms3.0里直接使用,若在其他地方使用请自己修改
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年11月15日
2024年11月15日
- 炉石传说月初最强卡组有哪些 2024月初最强上分卡组推荐
- 狼人杀亮相原生鸿蒙之夜 假面科技强势登陆华为生态
- 12小时光线挑战!AI画质专家才是大平层首选
- 2024游戏IP报告:1~9月规模1960亿 68%用户愿为之付费
- 群星.2024-今夜一起为爱鼓掌电视剧原声带【相信音乐】【FLAC分轨】
- BIGFOUR.2013-大家利事【寰亚】【WAV+CUE】
- 李美凤.1992-情深透全情歌集【EMI百代】【WAV+CUE】
- 田震2024-《时光音乐会》[金峰][WAV+CUE]
- 群星《监听天碟3》[LECD]限量版[WAV+CUE]
- 心妤《声如夏花HQ》头版限量编号[WAV+CUE]
- 群星《摇滚五杰》[低速原抓WAV+CUE][1.1G]
- 群星 《2024好听新歌30》十倍音质 U盘音乐 [WAV+分轨]
- 群星《试音草原·女声篇》经典蒙古民歌[WAV+CUE][1G]
- 陈慧娴《永远是你的朋友》头版限量编号MQA-UHQCD2024[低速原抓WAV+CUE]
- 曼丽·女人三十《如果·爱》限量1:1母盘直刻[低速原抓WAV+CUE]