日期:2014-05-18  浏览次数:20911 次

javascript刷新select组件
在jsp页面中做了两个select.第一个select中的内容是从数据库中读取..当选择其中一个值的时候..把这个值在上数据库中查找内容.查找到的内容放在第二个select中去.

问题是:功能实现了..可是点击第一个select中的值的时候.第二个select没结果..但是一刷新页面..第二个select就有结果了...问一下大家..我用什么语句可以自动刷新第二个select中的内容呢.

------解决方案--------------------
你数据怎么取的?

取到数据后执行

document.forms[0].s2.options.length = 0
for(i = 0;i <10;i++)
document.forms[0].s2.options[document.forms[0].s2.options.length] =new Option(i,i)
------解决方案--------------------
document.forms[0].s2.options.length = 0 把第二个select清空
for(i = 0;i <10;i++){循环给第二个select添加内容
document.forms[0].s2.options[document.forms[0].s2.options.length] =new Option(i,i)
}
------解决方案--------------------
我的代码是新生成第二个select的下拉框,
------解决方案--------------------
<script>
function changeOptionvalue(source,field){
var selectedValue = document.all[ "parentchannelnumber "].options[document.all.parentchannelnumber.selectedIndex].value;
var mySource = source.split( "| ");
for( i = 0; i < mySource.length ; i++ ){
var subSource = mySource[i].split( ", ");
if( subSource[0] == selectedValue ){
field.value = subSource[1];
}
}
}
</script>


<select name= "channellevel " class= "SeleteLevel ">
<option value= "1 "> 一级栏目 </option>
<option value= "2 "> 二级栏目 </option>
</select>


<select id= "parentchannelnumber " name= "parentchannelnumber " class= "SeleteLevel " onchange= "changeOptionvalue( ' <%=parentChannelNameSource%> ',document.channelmanager.parentchannelname) " >
<%
if( channelLevel != 2 ){
out.println( " <option value=1> 无上级栏目 </option> ");
}else{
out.println(showOptionSelected);
}
%>
</select>