ajax实现二级联动
来源:互联网 发布:vscode怎么编译运行 编辑:程序博客网 时间:2024/05/16 11:42
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>二级联动</title>
</head>
<body>
<select id="province">
<option>请选择</option>
</select>
<select id="city">
<option>请选择</option>
</select>
<script>
var xhr=getXhr();
window.onload=function(){
xhr.open("get","08.php?state=1");
xhr.send(null);
xhr.onreadystatechange=function(){
if(xhr.readyState==4&&xhr.status==200){
var data=xhr.responseText;
var provinces=data.split(",");
for(var i=0;i<provinces.length;i++){
var option=document.createElement("option");
var text=document.createTextNode(provinces[i]);
option.appendChild(text);
var province=docuemnt.getElementById("province");
province.appendChild(province);
}
}
}
}
var provinceEle=document.getElementById("province");
provinceEle.onchange=function(){
var city=document.getElementById("city");
var opts=city.getElementsByTagName("option");
for(var z=opts.length-1;z>0;z--){
city.removeChild(opts[z]);
}
if(provinceEle!="请选择"){
xhr.open("post","08.php");
xhr.send("state=2&province="+provinceEle.value);
xhr.onreadystatechange=function(){
if(xhr.readyState==4&&xhr.status==200){
var data=xhr.responseText;
var cities=data.split(",");
for(var i=0;i<cities.length;i++){
var option=document.createElement("option");
var text=document.createTextNode(cities[i]);
option.appendChild(text);
city.appendChild(option);
}
}
}
}
}
function getXhr(){
var xhr=null;
if(window.XMLHttpRequest){
xhr=new XMLHttpRequest();
}else{
xhr=new ActiveXObject('Microsoft.XMLHttp');
}
return xhr;
}
</html>
<html>
<head>
<meta charset="utf-8">
<title>二级联动</title>
</head>
<body>
<select id="province">
<option>请选择</option>
</select>
<select id="city">
<option>请选择</option>
</select>
<script>
var xhr=getXhr();
window.onload=function(){
xhr.open("get","08.php?state=1");
xhr.send(null);
xhr.onreadystatechange=function(){
if(xhr.readyState==4&&xhr.status==200){
var data=xhr.responseText;
var provinces=data.split(",");
for(var i=0;i<provinces.length;i++){
var option=document.createElement("option");
var text=document.createTextNode(provinces[i]);
option.appendChild(text);
var province=docuemnt.getElementById("province");
province.appendChild(province);
}
}
}
}
var provinceEle=document.getElementById("province");
provinceEle.onchange=function(){
var city=document.getElementById("city");
var opts=city.getElementsByTagName("option");
for(var z=opts.length-1;z>0;z--){
city.removeChild(opts[z]);
}
if(provinceEle!="请选择"){
xhr.open("post","08.php");
xhr.send("state=2&province="+provinceEle.value);
xhr.onreadystatechange=function(){
if(xhr.readyState==4&&xhr.status==200){
var data=xhr.responseText;
var cities=data.split(",");
for(var i=0;i<cities.length;i++){
var option=document.createElement("option");
var text=document.createTextNode(cities[i]);
option.appendChild(text);
city.appendChild(option);
}
}
}
}
}
function getXhr(){
var xhr=null;
if(window.XMLHttpRequest){
xhr=new XMLHttpRequest();
}else{
xhr=new ActiveXObject('Microsoft.XMLHttp');
}
return xhr;
}
</script>
08.php:
<?php
$state=$_REQUEST['state'];
if($state==1){
echo '山东省,辽宁省,吉林省';
}else{
$province=$_POST['province'];
switch (province){
case "山东省":
echo '青岛市,济南市,威海市,德州市,日照市';
break;
case "吉林省":
echo '长春市,松原市,吉林市,通化市,四平市';
break;
case "辽宁省":
echo '沈阳市,大连市,铁岭市,丹东市,锦州市';
break;
}
}
?>
</html>
0 0
- Ajax实现二级联动
- ajax实现二级联动
- AJAX实现二级联动
- Ajax实现二级联动菜单
- Ajax实现省市二级联动
- 非ajax实现二级联动
- Ajax实现二级联动菜单
- 用ajax实现二级联动
- Ajax实现二级联动菜单
- PHP + AJAX 实现二级联动
- Ajax实现二级联动菜单
- Ajax实现二级联动菜单
- PHP + AJAX 实现二级联动
- 用Ajax实现二级联动
- Ajax实现二级联动菜单
- EasyUi+Ajax实现二级联动
- 使用ajax实现二级联动
- Ajax实现二级联动下拉框
- java异常处理
- Android应用间通讯和数据共享
- 从键盘上输入任意的正整数,编程判断该数是否为回文数。 所谓的回文数就是从左到右读这个数与从右到左读这个数是一样的。 例如,12321 , 4004都是回文数。
- hdu 1754 I hate it (线段树)
- C#6.0 新新特性
- ajax实现二级联动
- linux正则表达式语法
- 人脸检测/Harr分类器
- iOS 获取判断手机屏幕尺寸,并判断手机系统版本
- 七牛云文件上传
- iOS图像文字识别
- 苹果
- PHP四种基本排序算法
- JavaScript学习——数据属性和访问器属性