怎么用jsp给select中options赋值

我的意思是我在form表单中插一个select元素。但select中没有option和他相关的值。但是当我单击其他一个元素(用onclick事件)时就给select中option分别赋值了。当我再次单击另一个元素(用onclick事件)又再次给select中option赋了另外的值
我说的是用脚本语言(如JavaScript)给select赋值。不是直接赋值。

在JS中先给select定义个id,通过var select=document.getElementById();取这个select,如果你要改变是的选中option的value的话就用select.option[select.selectedIndex].value给它赋值,如果你要改的是option显示的值的话~就只能用innerHTML了~select.option[select.selectedIndex].innerHTML
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2017-09-05
jsp给select中options赋值,参考方法如下:
var t = document.getElementById("select1");
var selectValue=t.options[t.selectedIndex].value;//获取select的值
var t1 = document.getElementById("select2");
for(i=0;i<t1.length;i++){//给select赋值
if(selectValue==t.options[i].value){
t1.options[i].selected=true
}
}
第2个回答  2008-12-29
你可以在select中直接给他赋值啊!
<select name="name">
<option>值1</option>
<option>值2</option>
<option>值3</option>
<option>值4</option>
<option>值5</option>
<option>值6</option>
</select>