`
liulanghan110
  • 浏览: 1064581 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

select 选择框设置值的问题

阅读更多
                                <select name="type" param='<@s.property value="tmsBox.type"/>' >
                                    <option value="0" >周转箱</option>
                                    <option value="1"  >虚拟箱</option>
                                </select>

select标签不能这样设置值<<select name="type" value = "1">

 

上面这段代码,<@是freemaker的调用函数的意思,这里是调用struts2的s.property 。这里是获取后台tmsBox.type的值赋值给property。这段代码在IE下可以设置select的值,但是在FIREFOX下却无效。

 

解决办法有两种:

1.在加载页面时调用一个JS函数,在JS函数里获取后台值并设置select下拉框的值。

 

document.getElementById("insteadId").options[0].selected = true;

 2.使用freemaker的方法,在每个options上判断。

<select name="type" >
          <option value="0"  <#if tmsBox.type?? && tmsBox.type == 0>selected="selected"</#if> >周转箱</option>
          <option value="1"  <#if tmsBox.type?? && tmsBox.type== 1>selected="selected"</#if> >虚拟箱</option>
  </select>

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics