在写页面时,经常要用到select标签,有一些效果我们经常使用。
1.? 在我们请求过服务器之后又返回到原来的jsp页面,如何让select选项在我们上次选择的那一项上面呢?
<script>
//页面加载时调用
window.onload=function(){
//服务器传一个上次所有的内容过来
var typeval= '${requestScope.type}';
var type= document.form1.type;
for(var i=0;i<type.options.length;i++){
//将上次那个选项置为选择状态
if(type.options[i].value==typeval){
type.options[i].selected=true;
break;
}
}
}
</script>
?
<select name="type"> <option>请选择</option> <option value="1">类1</option> <option value="2">类1</option> <option value="3">类1</option> </select>
?
?