簡體   English   中英

獲取所選項目的listValue <s:select> 在struts2中

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM