处理第一个下拉列表的onChange事件
解决方案 »
- Md5加密中 C#和Java得到的加密结果不同
- url上添加一个随机数
- struts框架中使用Fckeditor的时候不能上传文件是怎么回事?
- 网站后台管理
- 求救:后台java解析xml文件把数据显示在jsp页面,如何对循环表单修改和增加???
- 请问如何判断是否存在session?
- 如何取当前jsp的执行路径?
- 如何在JSP中操作COOKIES?
- java如何取得邮件服务器的mx记录,判断一个邮件地址如[email protected]是不是真的email地址?
- oracle jdbc查询到的数据和plsql 查询到的数据精度不同
- PHP or JSP 是个问题?
- 郁闷的问题,怎么看着说明都不通过!给分了!
如果不向后台提交的话,只能用javaSript实现。
新建立一个页面显示BEAN为: APAGE.CLASS,
新建立一个ATEMP.JSP, 在ATEMP.JSP中有: <JSP:USEBEAN CLASS=APAGE....>,这个文件加载后自动跳转到A.JSP. 选择第一个下拉框后,系统后台走了: A.JSP--> ATEMP.JSP-->A.JSP
第二个下拉框的显示内容由APAGE来控制, (APAGE用到的数据不自己产生, 它从SESSION里面取数据.按楼主说, 数据已经在SESSION里面的了)
有很多论坛,在注册时填写省市的时候都是这么做的,比如“雷傲论坛”,它是把某个省的所有城市名称放在一个字符串中,中间用一个符号间隔,30几个省的数据放在一个数组中……然后 JavaScript 编写……或者看看俺的方法……
---------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head><body>
<form name="form1" method="post" action="">
<p>
<select name="select1" onChange="onOfficeSelectChange();">
</select>
</p>
<p>
<select name="select2">
</select>
</p>
</form>
<script language="JavaScript" type="text/JavaScript">function CLabelValue (label, value)
{
this.label = label;
this.value = value;
}function CSectionOffice (label, value, OfficeID)
{
this.label = label;
this.value = value;
this.officeID = OfficeID;
}var theOffices = new Array (3);
theOffices[0] = new CLabelValue ("ÂÞºþË°Îñ¾Ö", "001");
theOffices[1] = new CLabelValue ("¸£ÌïË°Îñ¾Ö", "002");
theOffices[2] = new CLabelValue ("Éß¿ÚË°Îñ¾Ö", "003");var theSectionOffices = new Array (10);
theSectionOffices[0] = new CSectionOffice ("ÂÞºþ¿ÆÊÒ1", "001", "001");
theSectionOffices[1] = new CSectionOffice ("ÂÞºþ¿ÆÊÒ2", "002", "001");
theSectionOffices[2] = new CSectionOffice ("ÂÞºþ¿ÆÊÒ3", "003", "001");theSectionOffices[3] = new CSectionOffice ("¸£Ìï¿ÆÊÒ1", "004", "002");
theSectionOffices[4] = new CSectionOffice ("¸£Ìï¿ÆÊÒ2", "005", "002");
//theSectionOffices[5] = new CSectionOffice ("¸£Ìï¿ÆÊÒ3", "006", "002");
theSectionOffices[5] = {label:"¸£Ìï¿ÆÊÒ3", value:"006", officeID:"002"};theSectionOffices[6] = new CSectionOffice ("Éß¿Ú¿ÆÊÒ1", "007", "003");
theSectionOffices[7] = new CSectionOffice ("Éß¿Ú¿ÆÊÒ2", "008", "003");
//theSectionOffices[8] = new CSectionOffice ("Éß¿Ú¿ÆÊÒ3", "009", "003");
theSectionOffices[8] = {label:"Éß¿Ú¿ÆÊÒ3", value:"009", officeID:"003"};
theSectionOffices[9] = new CSectionOffice ("Éß¿Ú¿ÆÊÒ4", "010", "003");
var aNewElement;
for (var i=0; i<theOffices.length; i++)
{
aNewElement = document.createElement("OPTION");
aNewElement.text = theOffices[i].label;
aNewElement.value = theOffices[i].value;document.all.select1.options.add (aNewElement);
}
function onOfficeSelectChange ()
{
var OfficeID = document.all.select1.value;
var aNewElement;
var i;//alert ("you choose: " + OfficeID); // clear old options...
for (i=document.all.select2.length-1; i>=0; i--)
document.all.select2.remove (i); // ¿ÉÒÔÂ // create new options...
for (i=0; i<theSectionOffices.length; i++)
{
if (theSectionOffices[i].officeID == OfficeID)
{
aNewElement = document.createElement("OPTION");
aNewElement.text = theSectionOffices[i].label;
aNewElement.value = theSectionOffices[i].value;
document.all.select2.options.add (aNewElement);
}
}
}</script></body>
</html>
-------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head><body>
<form name="form1" method="post" action="">
<p>
<select name="select1" onChange="onOfficeSelectChange();" >
</select>
</p>
<p>
<select name="select2">
</select>
</p>
</form>
<script language="JavaScript" type="text/JavaScript">function CLabelValue (label, value)
{
this.label = label;
this.value = value;
}function CSectionOffice (label, value, OfficeID)
{
this.label = label;
this.value = value;
this.officeID = OfficeID;
}var theOffices = new Array (3);
theOffices[0] = new CLabelValue ("罗湖税务局", "001");
theOffices[1] = new CLabelValue ("福田税务局", "002");
theOffices[2] = new CLabelValue ("蛇口税务局", "003");var theSectionOffices = new Array (10);
theSectionOffices[0] = new CSectionOffice ("罗湖科室1", "001", "001");
theSectionOffices[1] = new CSectionOffice ("罗湖科室2", "002", "001");
theSectionOffices[2] = new CSectionOffice ("罗湖科室3", "003", "001");theSectionOffices[3] = new CSectionOffice ("福田科室1", "004", "002");
theSectionOffices[4] = new CSectionOffice ("福田科室2", "005", "002");
//theSectionOffices[5] = new CSectionOffice ("福田科室3", "006", "002");
theSectionOffices[5] = {label:"福田科室3", value:"006", officeID:"002"};theSectionOffices[6] = new CSectionOffice ("蛇口科室1", "007", "003");
theSectionOffices[7] = new CSectionOffice ("蛇口科室2", "008", "003");
//theSectionOffices[8] = new CSectionOffice ("蛇口科室3", "009", "003");
theSectionOffices[8] = {label:"蛇口科室3", value:"009", officeID:"003"};
theSectionOffices[9] = new CSectionOffice ("蛇口科室4", "010", "003");
var aNewElement;
for (var i=0; i<theOffices.length; i++)
{
aNewElement = document.createElement("OPTION");
aNewElement.text = theOffices[i].label;
aNewElement.value = theOffices[i].value;document.all.select1.options.add (aNewElement);
}
function onOfficeSelectChange ()
{
var OfficeID = document.all.select1.value;
var aNewElement;
var i;//alert ("you choose: " + OfficeID); // clear old options...
for (i=document.all.select2.length-1; i>=0; i--)
document.all.select2.remove (i); // 可以嘛? // create new options...
for (i=0; i<theSectionOffices.length; i++)
{
if (theSectionOffices[i].officeID == OfficeID)
{
aNewElement = document.createElement("OPTION");
aNewElement.text = theSectionOffices[i].label;
aNewElement.value = theSectionOffices[i].value;
document.all.select2.options.add (aNewElement);
}
}
}</script></body>
</html>
同时,在客户端jsp只是在画面load的时候解析一次,生成静态的html,里面的java source都变成了固定条件下的固定值,无法再进行新的判断,新的操作。
所以如果想在客户端完成的话,首先在画面load的时候就要把jsp中的数据(多条)传递给javaScript数组,当画面触发了某些事件的时候,由javaScript来作处理。如果你想后台提交的话当我没说。