<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'menu.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<script type="text/javascript">
var len = document.forms[0].select1.options.length;
var optionTest = new Array(len);
for(var i=0; i<len; i++) {
optionTest[i] = new Array();
}
optionTest[0][0] = new Option("请选择");
optionTest[1][0] = new Option("马克思主义思想");
optionTest[1][1] = new Option("邓小平理论");
optionTest[1][2] = new Option("毛泽东的军事才华");
optionTest[1][3] = new Option("人民代表大会的含义");
optionTest[2][0] = new Option("姚明");
optionTest[2][1] = new Option("易建联");
optionTest[2][2] = new Option("刘翔");
optionTest[2][3] = new Option("郑洁");
function TwoMenu() {
document.forms[0].select2.options.length=0;
var select2 = document.forms[0].select2;
var index = document.forms[0].select1.options.selectedIndex;
for(var j=0; j<optionTest[index].length; j++) {
select2.options[j] = new Option(optionTest[index][j].text,optionTest[index][j].value);
}
}
</script> <body>
<form name="forms1" action="">
<select id="select1" name="select1" onchange="TwoMenu();">
<option value="0" selected>请选择</option>
<option value="1">政治</option>
<option value="2">体育</option>
</select>
<select id="select2" name="select2" >
<option value="0" selected>请选择</option>
</select>
</form>
</body>
</html>
说明:我把optionTest定义在全局变量里,下面的方法应该能得到这个对象,这里为什么不行
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'menu.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
--> </head>
<script type="text/javascript">
var len = document.forms[0].select1.options.length;
var optionTest = new Array(len);
for(var i=0; i<len; i++) {
optionTest[i] = new Array();
}
optionTest[0][0] = new Option("请选择");
optionTest[1][0] = new Option("马克思主义思想");
optionTest[1][1] = new Option("邓小平理论");
optionTest[1][2] = new Option("毛泽东的军事才华");
optionTest[1][3] = new Option("人民代表大会的含义");
optionTest[2][0] = new Option("姚明");
optionTest[2][1] = new Option("易建联");
optionTest[2][2] = new Option("刘翔");
optionTest[2][3] = new Option("郑洁");
function TwoMenu() {
document.forms[0].select2.options.length=0;
var select2 = document.forms[0].select2;
var index = document.forms[0].select1.options.selectedIndex;
for(var j=0; j<optionTest[index].length; j++) {
select2.options[j] = new Option(optionTest[index][j].text,optionTest[index][j].value);
}
}
</script> <body>
<form name="forms1" action="">
<select id="select1" name="select1" onchange="TwoMenu();">
<option value="0" selected>请选择</option>
<option value="1">政治</option>
<option value="2">体育</option>
</select>
<select id="select2" name="select2" >
<option value="0" selected>请选择</option>
</select>
</form>
</body>
</html>
说明:我把optionTest定义在全局变量里,下面的方法应该能得到这个对象,这里为什么不行
楼主【liuxinghua60】截止到2008-07-11 09:58:20的历史汇总数据(不包括此帖):
发帖的总数量:7 发帖的总分数:320 每贴平均分数:45
回帖的总数量:3 得分贴总数量:0 回帖的得分率:0%
结贴的总数量:1 结贴的总分数:50
无满意结贴数:0 无满意结贴分:0
未结的帖子数:6 未结的总分数:270
结贴的百分比:14.29 % 结分的百分比:15.63 %
无满意结贴率:0.00 % 无满意结分率:0.00 %
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href=" <%=basePath%>">
<title>My JSP 'menu.jsp' starting page </title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">
function onloadFunction(){
var len = document.forms[0].select1.options.length;
optionTest = new Array(len);
for(var i=0; i <len; i++) {
optionTest[i] = new Array();
}
optionTest[0][0] = new Option("请选择");
optionTest[1][0] = new Option("马克思主义思想");
optionTest[1][1] = new Option("邓小平理论");
optionTest[1][2] = new Option("毛泽东的军事才华");
optionTest[1][3] = new Option("人民代表大会的含义");
optionTest[2][0] = new Option("姚明");
optionTest[2][1] = new Option("易建联");
optionTest[2][2] = new Option("刘翔");
optionTest[2][3] = new Option("郑洁");
}
function TwoMenu() {
document.forms[0].select2.options.length=0;
var select2 = document.forms[0].select2;
var index = document.forms[0].select1.options.selectedIndex;
for(var j=0; j <optionTest[index].length; j++) {
select2.options[j] = new Option(optionTest[index][j].text,optionTest[index][j].value);
}
}
onload = onloadFunction;
</script>
</head>
<body>
<form name="forms1" action="">
<select id="select1" name="select1" onchange="TwoMenu();">
<option value="0" selected>请选择 </option>
<option value="1">政治 </option>
<option value="2">体育 </option>
</select>
<select id="select2" name="select2" >
<option value="0" selected>请选择 </option>
</select>
</form>
</body>
</html>