简体   繁体   English

获取所选项目的listValue <s:select> 在struts2中

[英]obtain listValue of selected item in <s:select> in struts2

I have a JSP page which uses an <s:select> tag. 我有一个使用<s:select>标签的JSP页面。

<s:select 
        id="userGroups"
        headerKey="-1"
        headerValue="------ Select Group ------" list="userGroupList"
        listValue="groupName"
        onchange="selectGroup()">   

what i want to achieve is to display the listValue of the selected item using a javascript function. 我想要实现的是使用javascript函数显示所选项的listValue。 what may be the way to do this? 这可能是怎么回事?

EDIT: my selectGroup() function: 编辑:我的selectGroup()函数:

function selectGroup(){
    var selectedGroup = document.getElementById('userGroups');
    alert(selectedGroup.value);
}
function selectGroup(){
    var sel = document.getElementById('userGroups');
    alert(sel.options[sel.selectedIndex].text);
}

or 要么

<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);
}

or 要么

<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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM