AJAX+Prototype的联动菜单

客户端代码 select.html
[html]
<html>
<head>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache, must-revalidate">
<meta http-equiv="expires" content="0">
<script language="javascript" src="js/prototype.js"></script>
<script language="javascript">
function sel(str){
if(str==0)return false;
var options = {
method:"get",
asynchronous:true,
parameters:"id="+str,
onSuccess:function(transport,json){
var doc = transport.responseText;
var list = doc.split("|");
$("class").options.length = 1;
for(var i=0;i<list.length-1;i++){
var temp = list.strip().split(",");
$("class").add(new Option(temp[1],temp[0]));
}
},
onFailure:function(transport,json){
alert("调试失败");
}
}
new Ajax.Request("ajax.php",options);
}
</script>
<head>
<body>
<select id="type" οnchange="javascript:sel(this.value);">
<option value="0">请选择</option>
<option value="1">公司</option>
<option value="2">电话</option>
<option value="3">传真</option>
</select>
<select id="class">
<option value="0">请选择</option>
</select>
</body>
</html>
[/html]
服务端代码 ajax.php
[php]
<?php
header('Content-Type:text/html;charset=GB2312');
header("expires:mon,26jul199705:00:00gmt");
header("cache-control:no-cache,must-revalidate");
header("pragma:no-cache");

$id = $_GET['id'];

switch ($id){
case 1;
print "1,1号公司|2,2号公司|3,3号公司|";
break;
case 2;
print "1,1号电话|2,2号电话|3,3号电话|";
break;
case 3;
print "1,1号传真|2,2号传真|3,3号传真|";
break;
}
?>
[/php]
演示地址:http://www.lueying.cn/index/select.php

3级联动
3级联动
[html]
<html>
<head>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache, must-revalidate">
<meta http-equiv="expires" content="0">
<script language="javascript" src="js/prototype.js"></script>
<script language="javascript">
function sel(idname,str,act){
if(str==0)return false;
var options = {
method:"get",
asynchronous:true,
parameters:act+"="+str,
onSuccess:function(transport,json){
var doc = transport.responseText;
var list = doc.split("|");
$(idname).options.length = 1;
for(var i=0;i<list.length-1;i++){
var temp = list.strip().split(",");
$(idname).add(new Option(temp[1],temp[0]));
}
},
onFailure:function(transport,json){
alert("调试失败");
}
}
new Ajax.Request("ajax.php",options);
}
</script>
<head>
<body>
<select id="type" οnchange="javascript:sel('class',this.value,'id');">
<option value="0">请选择</option>
<option value="1">公司</option>
<option value="2">电话</option>
<option value="3">传真</option>
</select>
<select id="class" οnchange="javascript:sel('three',this.value,'pid');">
<option value="0">请选择</option>
</select>
<select id="three">
<option value="0">请选择</option>
</select>
</body>
</html>
[/html]
[php]
<?php
header('Content-Type:text/html;charset=GB2312');
header("expires:mon,26jul199705:00:00gmt");
header("cache-control:no-cache,must-revalidate");
header("pragma:no-cache");

if(isset($_GET['id'])){
switch ($_GET['id']){
case 1;
print "1,1号公司|2,2号公司|3,3号公司|";
break;
case 2;
print "1,1号电话|2,2号电话|3,3号电话|";
break;
case 3;
print "1,1号传真|2,2号传真|3,3号传真|";
break;
}
}
if(isset($_GET['pid'])){
switch ($_GET['pid']){
case 1;
print "1,11号公司|2,22号公司|3,33号公司|";
break;
case 2;
print "1,11号电话|2,22号电话|3,33号电话|";
break;
case 3;
print "1,11号传真|2,22号传真|3,33号传真|";
break;
}
}

?>
[/php]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值