菜单级联简单例子

<%@ page contentType="text/html; charset=GBK"%>
<html>
<head>
<title>下拉列表联动</title>
</head>
<body bgcolor="#ffffff">
	<table>
		<tr>
			<td><select name="s1" onChange="haha()">
					<option value="null">请选择
					<option value="1">1
					<option value="2">2
					<option value="3">3
					<option value="4">4
			</select>
			</td>
			<td id="heihei"><select>
					<option>请先选择第一个下拉
			</select>
			</td>
		</tr>
	</table>
	<script>
		//定义XMLHttpRequest对象
		var http_request = false;

		function send_request(url) {
			http_request = false;
			//开始初始化XMLHttpRequest对象
			if (window.XMLHttpRequest) {//Mozilla等浏览器初始化XMLHttpRequest过程
				http_request = new XMLHttpRequest();
				//有些版本的Mozilla浏览器处理服务器返回的未包含XML mime-type头部信息的内容时会出错.
				//因此,要确保返回的内容包含text/xml信息.
				if (http_request.overrideMimeType) {
					http_request.overrideMimeType("text/xml");
				}
			} else if (window.ActiveXObject) {//IE浏览器初始化XMLHttpRequest过程
				try {
					http_request = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e) {
					try {
						http_request = new ActiveXObject("Microsoft.XMLHTTP");
					} catch (e) {
					}
				}
			}
			//异常,创建对象失败
			if (!http_request) {
				window.alert("不能创建XMLHttpRequest对象实例!");
				return false;
			}
			//指定响应处理函数
			http_request.onreadystatechange = processRequest;
			//发送HTTP请求信息
			http_request.open("GET", url, true);
			http_request.send(null);
		}

		//处理返回信息函数
		function processRequest() {
			//判断对象状态
			if (http_request.readyState == 4) {
				//判断HTTP状态码
				if (http_request.status == 200) {
					//信息已经成功返回
					//window.document.write(http_request.responseText);
					//alert(http_request.responseText);
					document.getElementById("heihei").innerHTML = http_request.responseText;
				} else {
					//请求页面有问题
					alert("您所请求的页面有异常!错误状态:" + http_request.status);
				}
			}
		}

		function haha() {
			var flag = document.all("s1").value;
			send_request("b.jsp?flag=" + flag);
		}
	</script>
</body>
</html>

 

<%@ page contentType="text/html; charset=GB2312"%>
<%
  String flag=request.getParameter("flag");
  if("1".equals(flag)){
%>

<select name="s2">
	<option value="a">a
	<option value="b">b
	<option value="c">c
	<option value="d">d
</select>

<%
  }else if("2".equals(flag)){
%>

<select name="s2">
	<option value="e">e
	<option value="f">f
	<option value="g">g
	<option value="h">h
</select>
<%
  }else{
%>
<select name="s2">
	<option value="null">此项没有内容
</select>
<%
  }
%>
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值