JSP里怎么实现三级联动呢?
在JSP的页里,我想做一个省、市、县的三级联动,可是不是知道如何写,谁能帮帮我,给我一个源代码呢?...
在JSP的页里,我想做一个省、市、县的三级联动,可是不是知道如何写,谁能帮帮我,给我一个源代码呢?
展开
4个回答
展开全部
这是一个两级联动 自己看看把。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=gb2312">
<TITLE>学期课程</TITLE>
<SCRIPT language="JavaScript" >
function changeTerm( )
{
var courseList = new Array( );
courseList['第一学期'] = ['C', 'SqlServer基础', 'C#', 'HTML'];
courseList['第二学期'] =['Java','JavaScript', 'SqlServer高级', 'Java数据结构', 'JSP'];
courseList['第二学年'] = ['Oracle','Struts', 'EJB3.0', 'Ajax','Spring','Hibernate'];
//获得学期选项的索引号,如第一学期为1,比对应数组索引号多1
var pIndex=document.myform.selTerm.value;
var newOption1;
document.myform.selCourse.options.length=0;
for (var j in courseList[pIndex])
{
newOption1=new Option(courseList[pIndex][j], courseList[pIndex][j]);
document.myform.selCourse.options.add(newOption1);
}
}
</SCRIPT>
</HEAD>
<BODY>
<FORM name="myform" id="myform" action="register_success.htm" onSubmit="return checkForm( )" >
<TABLE border="0" align="center" >
<TR>
<TD colspan="2" align="center">考 试 申 请</TD>
</TR>
<TR>
<TD>学期</TD>
<TD><SELECT name="selTerm" onChange="changeTerm( )">
<OPTION>--请选择学期--</OPTION>
<OPTION value="第一学期">第一学期</OPTION>
<OPTION value="第二学期">第二学期</OPTION>
<OPTION value="第二学年">第二学年</OPTION>
</SELECT></TD>
</TR>
<TR>
<TD>课程</TD>
<TD><SELECT name="selCourse" >
<OPTION>--请选择对应学期的课程--</OPTION>
</SELECT></TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=gb2312">
<TITLE>学期课程</TITLE>
<SCRIPT language="JavaScript" >
function changeTerm( )
{
var courseList = new Array( );
courseList['第一学期'] = ['C', 'SqlServer基础', 'C#', 'HTML'];
courseList['第二学期'] =['Java','JavaScript', 'SqlServer高级', 'Java数据结构', 'JSP'];
courseList['第二学年'] = ['Oracle','Struts', 'EJB3.0', 'Ajax','Spring','Hibernate'];
//获得学期选项的索引号,如第一学期为1,比对应数组索引号多1
var pIndex=document.myform.selTerm.value;
var newOption1;
document.myform.selCourse.options.length=0;
for (var j in courseList[pIndex])
{
newOption1=new Option(courseList[pIndex][j], courseList[pIndex][j]);
document.myform.selCourse.options.add(newOption1);
}
}
</SCRIPT>
</HEAD>
<BODY>
<FORM name="myform" id="myform" action="register_success.htm" onSubmit="return checkForm( )" >
<TABLE border="0" align="center" >
<TR>
<TD colspan="2" align="center">考 试 申 请</TD>
</TR>
<TR>
<TD>学期</TD>
<TD><SELECT name="selTerm" onChange="changeTerm( )">
<OPTION>--请选择学期--</OPTION>
<OPTION value="第一学期">第一学期</OPTION>
<OPTION value="第二学期">第二学期</OPTION>
<OPTION value="第二学年">第二学年</OPTION>
</SELECT></TD>
</TR>
<TR>
<TD>课程</TD>
<TD><SELECT name="selCourse" >
<OPTION>--请选择对应学期的课程--</OPTION>
</SELECT></TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
展开全部
一:JS文件:
复制代码
function Dsy(){
this.Items = {};
}
Dsy.prototype.add = function(id,iArray)
{
this.Items[id] = iArray;
}
Dsy.prototype.Exists = function(id)
{
if(typeof(this.Items[id]) == "undefined") return false;
return true;
}
function change(v){
var str="0";
for(i=0;i<v;i++){ str+=("_"+(document.getElementById(s[i]).selectedIndex-1));};
var ss=document.getElementById(s[v]);
with(ss){
length = 0;
options[0]=new Option(opt0[v],opt0[v]);
if(v && document.getElementById(s[v-1]).selectedIndex>0 || !v)
{
if(dsy.Exists(str)){
ar = dsy.Items[str];
for(i=0;i<ar.length;i++)options[length]=new Option(ar[i],ar[i]);
if(v)options[1].selected = true;
}
}
if(++v<s.length){change(v);}
}
}
var dsy = new Dsy();
dsy.add ("0",["一年级","二年级"]);
dsy.add("0_0",["一班","二班"]);
dsy.add("0_0_0",["数学","语文"]);
dsy.add("0_0_1",["数学","语文"]);
dsy.add("0_1",["一班","二班","三班"]);
dsy.add("0_1_0",["数学","语文","英语","美术"]);
dsy.add("0_1_1",["数学","语文","英语","美术"]);
dsy.add("0_1_2",["数学","语文","英语","美术"]);
var s=["province","city","county"];
var opt0 = ["年级","班组","科目"];
function setup(){
for(i=0;i<s.length-1;i++)
document.getElementById(s[i]).onchange=new Function("change("+(i+1)+")");
change(0);
}
二:联动表单,html文件
复制代码
<script language="javascript" src="1.js"></script>
<form id="Form1" method="post" runat="server">
<Select id="province" runat="server" NAME="province"></Select>
<Select id="city" runat="server" NAME="city"></Select>
<Select id="county" runat="server" NAME="city"></Select>
</form>
<SCRIPT language="javascript">
setup()
</SCRIPT>
复制代码
function Dsy(){
this.Items = {};
}
Dsy.prototype.add = function(id,iArray)
{
this.Items[id] = iArray;
}
Dsy.prototype.Exists = function(id)
{
if(typeof(this.Items[id]) == "undefined") return false;
return true;
}
function change(v){
var str="0";
for(i=0;i<v;i++){ str+=("_"+(document.getElementById(s[i]).selectedIndex-1));};
var ss=document.getElementById(s[v]);
with(ss){
length = 0;
options[0]=new Option(opt0[v],opt0[v]);
if(v && document.getElementById(s[v-1]).selectedIndex>0 || !v)
{
if(dsy.Exists(str)){
ar = dsy.Items[str];
for(i=0;i<ar.length;i++)options[length]=new Option(ar[i],ar[i]);
if(v)options[1].selected = true;
}
}
if(++v<s.length){change(v);}
}
}
var dsy = new Dsy();
dsy.add ("0",["一年级","二年级"]);
dsy.add("0_0",["一班","二班"]);
dsy.add("0_0_0",["数学","语文"]);
dsy.add("0_0_1",["数学","语文"]);
dsy.add("0_1",["一班","二班","三班"]);
dsy.add("0_1_0",["数学","语文","英语","美术"]);
dsy.add("0_1_1",["数学","语文","英语","美术"]);
dsy.add("0_1_2",["数学","语文","英语","美术"]);
var s=["province","city","county"];
var opt0 = ["年级","班组","科目"];
function setup(){
for(i=0;i<s.length-1;i++)
document.getElementById(s[i]).onchange=new Function("change("+(i+1)+")");
change(0);
}
二:联动表单,html文件
复制代码
<script language="javascript" src="1.js"></script>
<form id="Form1" method="post" runat="server">
<Select id="province" runat="server" NAME="province"></Select>
<Select id="city" runat="server" NAME="city"></Select>
<Select id="county" runat="server" NAME="city"></Select>
</form>
<SCRIPT language="javascript">
setup()
</SCRIPT>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
正常情况下,3级联动是不存在的,也没有这么灵活的要求。
无非是1影响2、3;2影响3;从而实现看似层级的效果而已。多少级都无所谓。
无非是1影响2、3;2影响3;从而实现看似层级的效果而已。多少级都无所谓。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询