【问题标题】:How to get Selected option value from html:options collections如何从 html:options 集合中获取 Selected 选项值
【发布时间】:2013-07-15 20:04:14
【问题描述】:

我的 JSP 中有一个下拉菜单。如何从 JSP 中的<html:options> 标记中获取选定的值。

<html:select property="temp_Id"  >  
<html:options collection="listmap" property="key"/>  
</html:select>  

【问题讨论】:

  • 我想在脚本中选择值

标签: java javascript jsp struts jsp-tags


【解决方案1】:

把你的标签改成

<html:select property="temp_Id" styleId = "tempId" >
html:options collection="listmap" property="key"/>  
</html:select>

在您的 java 脚本中添加以下内容

var e = document.getElementById("tempId");
var strUser = e.options[e.selectedIndex].value;  

应该可以。谢谢。

【讨论】:

  • 根据 TLD 选择标签的属性 id 无效
  • 感谢 ArunM。如何从 HashMap 中获取选定键的值
  • javascript 将只从 HashMap 中获取密钥。不知道你在找什么。
  • 我想遍历 Hashmap 并想要选择 Key 的值
  • 这听起来很奇怪.. 你为什么要这样做?如果您可以将值显示为选项的标签,那么试试这个
猜你喜欢
  • 2023-03-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多