<?php
require_once ('data_Arr.php');
?>
<!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" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="author" content="zhuanghua" />
<title>菜单联动</title>
<script>
var xmlhttp=null;
function is_ajax(){
try{
xmlhttp=new XMLHttpRequest();
}catch(e){
try{
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
alert('浏览器不支持ajax!');
return false;
}
}
}
}
</script>
</head>
<body>
<select id="sel" onchange="sel_change(this.value)">
<option>请选择</option>
<?php
$query="select f_id from menu where type=1";
$result=mysql_query($query,$conn);
while($rows=mysql_fetch_row($result)){
if(array_key_exists($rows[0],$data)){
?>
<option value="<?php echo $rows[0]; ?>"><?php echo $data[$rows[0]]; ?></option>
<?php
}
}
?>
</select>
<select id="two" onchange="sel_two_change(this.value)">
<option>请选择 </option>
</select>
<select id="three">
<option>请选择</option>
</select>
<script>
function sel_change(value){
is_ajax();
var url="show_two.php?f_id="+value+'&'+Math.random();
xmlhttp.open('GET',url,true);
xmlhttp.onreadystatechange=show_two;
xmlhttp.send(null);
}
function show_two(){
if(xmlhttp.readyState==4){
if(xmlhttp.status==200){
var text=xmlhttp.responseText;
var json=eval("("+text+")");//转换为json对象
var selObj=document.getElementById('two');
selObj.options.length=null;
selObj.options.add(new Option('请选择',''));
for( i in json){
selObj.options.add(new Option(''+json[i]+'',''+i+''))
}
}
}
}
function sel_two_change(value){
is_ajax();
var url="show_three.php?f_id="+value+'&'+Math.random();
xmlhttp.open('GET',url,true);
xmlhttp.onreadystatechange=show_three;
xmlhttp.send(null);
}
function show_three(){
if(xmlhttp.readyState==4){
if(xmlhttp.status==200){
var text=xmlhttp.responseText;
var json=eval("("+text+")");//转换为json对象
var selObj=document.getElementById('three');
selObj.options.length=null;
selObj.options.add(new Option('请选择',''));
for( i in json){
selObj.options.add(new Option(''+json[i]+'',''+i+''))
}
}
}
}
</script>
</body>
</html>
- 1
- 2
前往页