级联下拉

2009-10-29 09:31

Ajax.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>ajax demo</title>
<meta http-equiv = "content-type" content = "text/html; charset=utf-8" />
<script type="text/javascript">
var xmlhttp;
var province;
function createXMLHttpRequest()
{
//xmlhttp=null;
if (window.XMLHttpRequest)
{// code for all new browsers
xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{// code for IE5 and IE6
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
function change()
{
createXMLHttpRequest();
// province=document.getElementById("province").value;
provinces=document.getElementById("province");
province=provinces.options[provinces.selectedIndex].text;
alert(province);
if (xmlhttp!=null)
{
thedate = new Date();

var url = "menu.php?province="+ encodeURI(province) + "&tick=" + thedate.getMilliseconds() ;
xmlhttp.open("GET",url,true);
alert(url);
xmlhttp.onreadystatechange=state_Change;
xmlhttp.send(null);
}
else
{
alert("Your browser does not support XMLHTTP.");
}
}

function state_Change()
{
if (xmlhttp.readyState==4)
{
if (xmlhttp.status==200)
    {
    var result = xmlhttp.responseText;
alert("result:/t"+result);
    result= result.split(",");
alert("result2222:/t"+result);
    var list = document.all.city;
    list.options.length = 0;
    list.options.add(new Option("---请选择---", ""));
    for (var i = 0; i < result.length; i++) {
        list.options.add(new Option(result[i]));
    }
    }
else
    {
    alert("Problem retrieving XML data");
    }
}
}
</script>
</head>
<body>
    省份:
<select id="province" οnchange="change();">
        <option selected="selected">河北</option>
        <option>北京</option>
        <option>山东</option>
    </select>
城市:
    <select id="city">
        <option selected="selected">邯郸</option>
    </select>

</body>
</html>

menu.php

<?php
//header("content = 'text/html; charset=gb2312'");

$get=$_GET["province"];
if($get)
{
$out="";
switch($get)
{
   case "河北":
   $out="保定,石家庄,邢台";
   break;
   case "北京":
   $out="东城区,宣武区,朝阳区";
   break;
   case "山东":
   $out="济南,临沂";
   break;
}
//$out=iconv("utf-8","gb2312//IGNORE",$out);
echo $out;
}
?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值