MyException - 我的异常网
当前位置:我的异常网» Java Web开发 » 下拉框动态对应有关问题

下拉框动态对应有关问题(2)

www.MyException.Cn  网友分享于:2013-12-22  浏览:879次

arrPlaceKb123List[ <bean:write name= "index " /> ][2]= " <bean:write name= "item1 " property= "placeKb3 " /> ";
arrPlaceKb123List[ <bean:write name= "index " /> ][3]= " <bean:write name= "item1 " property= "placeKb3Name " /> ";
</logic:iterate>
//===============================================================================================
function setPlace(t){

var elem1=document.forms[0].placeKb1;
var elem2=document.forms[0].placeKb2;
var elem3=document.forms[0].placeKb3;
var elem2Value=elem2.value;
var elem3Value=elem3.value;
var i;
var j;

if (t=1) {
//有第1个下拉的值,确定第2个下拉列表
elem2.length = 1; //清空下拉列表
j=0;
for (i=0; i <arrPlaceKb12List.length; i++) {
if (elem1.value==arrPlaceKb12List[i][0] || elem1.value== " ") {
//方法1
//elem2.options.add(new Option(arrPlaceKb12List[i][2], arrPlaceKb12List[i][1]));

//方法2
j++;
elem2.options[j] = new Option(arrPlaceKb12List[i][2]);
elem2.options[j].value = arrPlaceKb12List[i][1];
}
}

//选定先前elem2的值,如果相应下拉框没有此值,则flag位为1
var elem2Flag=1;
elem2.value = " ";
for (i=0; i <elem2.length; i++) { //或者用elem2.options.length
if (elem2.options[i].value == elem2Value) elem2Flag = 0;
}
if (elem2Flag == 0) elem2.value = elem2Value;
}

//有第2个下拉的值,确定第3个下拉列表
elem3.length = 1; //清空下拉列表
j=0;
for (i=0; i <arrPlaceKb123List.length; i++) {
if ((elem1.value==arrPlaceKb123List[i][0] && elem2.value==arrPlaceKb123List[i][1] )|| (elem1.value== " " && elem2.value== " ")) {

j++;
elem3.options[j] = new Option(arrPlaceKb123List[i][3]);
elem3.options[j].value = arrPlaceKb123List[i][2];
}
}

//选定先前elem3的值,如果相应下拉框没有此值,则flag位为1
var elem3Flag=1;
elem3.value = " ";
for (i=0; i <elem3.length; i++) { //或者用elem3.options.length
if (elem3.options[i].value == elem3Value) elem3Flag = 0;
}
if (elem3Flag == 0) elem3.value = elem3Value;
}
===============================================================================
对应的JSP中写:
-------------------------------------------
<TR>
<TD>
<bean:define id= "placeKb1List " name= "outputBean " property= "placeKb1Bean " type= "java.util.ArrayList " />
<html:select property= "placeKb1 " onchange= "setPlace(1) ">
<html:options collection= "placeKb1List " property= "placeKb1 " labelProperty= "placeKb1Name " />
</html:select>
</TD>
<TD> 省 </TD>
<TD>
<bean:define id= "placeKb2List " name= "outputBean " property= "placeKb2Bean " type= "java.util.ArrayList " />
<html:select property= "placeKb2 " onchange= "setPlace(2) ">
<html:options collection= "placeKb2List " property= "value " labelProperty= "label " />

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有