在jsp页面上,获取redis数据库中的数组,并显示在上面如:
" selected="selected"><%=RedisUtil.getJedis().lindex("sMonth",0) %>
" selected="selected"><%=RedisUtil.getJedis().lindex("sMonth",1) %>
" selected="selected"><%=RedisUtil.getJedis().lindex("sMonth",2) %>
请问怎么去判断select选中的就是显示的值,即,提交表单后刷新页面仍旧是选中的值。因为没有积分,所以不能给,十分抱歉,谢谢!
从后台返回一个数据,然后在页面加载完成之后,用程序或者js让select选中.
我是这么做的,但是每次点击查询提交数据后就刷新,再次加载后又回复默认值了。
$(document).ready(function(){
var staVal = $('#staID option:selected').text();//select选中的显示文本
var opt1 = $("#staID").get(0).options[2].text;
var opt2 = $("#staID").get(0).options[1].text;
var opt3 = $("#staID").get(0).options[0].text;
alert(opt1+":"+opt2+":"+opt3+":"+staVal);
if(staVal==opt1){
$("#staID").find("option[text='"+opt1+"']").attr("selected",true);
return true;
}
if(staVal==opt2){
$("#staID").find("option[text='"+opt2+"']").attr("selected",true);
return true;
}
if(staVal==opt3){
$("#staID").find("option[text='"+opt3+"']").attr("selected",true);
return true;
}
});
先取得选中的值 设为value1
在页面循环列表进行展示的时候使用 selected="selected"/c:if判断,判断条件为item.value == value1
先取得选中的值 设为value1
在页面循环列表进行展示的时候使用
<c:if>selected="selected"</c:if>
判断,判断条件为item.value == value1
解决了。用jstl嵌套jsp小脚本就可以做到。