<%@ 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>
<%
}
%>