[英]Getting the selected listValue of <s:select> in javascript
[英]obtain listValue of selected item in <s:select> in struts2
我有一个使用<s:select>
标签的JSP页面。
<s:select
id="userGroups"
headerKey="-1"
headerValue="------ Select Group ------" list="userGroupList"
listValue="groupName"
onchange="selectGroup()">
我想要实现的是使用javascript函数显示所选项的listValue。 这可能是怎么回事?
编辑:我的selectGroup()函数:
function selectGroup(){
var selectedGroup = document.getElementById('userGroups');
alert(selectedGroup.value);
}
function selectGroup(){
var sel = document.getElementById('userGroups');
alert(sel.options[sel.selectedIndex].text);
}
要么
<s:select
id="userGroups"
headerKey="-1"
headerValue="------ Select Group ------" list="userGroupList"
listValue="groupName"
onchange="selectGroup(this)">
function selectGroup(sel){
alert(sel.options[sel.selectedIndex].text);
}
要么
<s:select
id="userGroups"
headerKey="-1"
headerValue="------ Select Group ------" list="userGroupList"
listValue="groupName"
onchange="alert(this.options[this.selectedIndex].text);">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.