在Struts2中通过jquery调用Ajax

在Struts2中通过jquery调用Ajax,struts2,Struts2,问题是我有3个下拉列表,我通过从action类检索的映射设置了第二个组合框,现在如果我使用 var sub_cat=$("#selecSubCat").val(); //id for second text box is the selecSubCat 如何获取所选选项的文本值而不是0和1。您可以使用以下代码获取所选选项的文本 var v= $("#selecSubCat option:selected").text(); 动作类 private Map usernameList=new

问题是我有3个下拉列表,我通过从action类检索的映射设置了第二个组合框,现在如果我使用

var sub_cat=$("#selecSubCat").val(); //id for second text box is the selecSubCat

如何获取所选选项的文本值而不是0和1。

您可以使用以下代码获取所选选项的文本

var v= $("#selecSubCat option:selected").text();  
动作类

private Map usernameList=new HashMap();

public Map getUsernameList() {
    usernameList=new HashMap();
    usernameList.put("1","ram");
    usernameList.put("2","jhon");
    return usernameList;
}

public void setUsernameList(Map usernameList) {
    this.usernameList = usernameList;
}
若并没有特别提到listKey,listValue它默认将map key作为listKey,map value为listValue

  <s:select  id="selecSubCat" label="Select UserName "
    listKey="value" listValue="value"
    // listKey="key" listValue="value"   // default assigned map value like this
    list="usernameList" 
    name="yourSearchEngine" 
    value="defaultSearchEngine" />
它应该给你的文本值

这解决了我的问题

$('#selecSubCat'.children("option").filter(":selected").text();
$('#selecSubCat'.children("option").filter(":selected").text();