<s:select list="#request.listinfo" headerKey="000" headerValue="请选择"
id="infos" name="infos" listKey="id" listValue="name" >
1、headerKey是默认值的key即选择默认值的value时,就会弹出headerKey即$("#info").val()就是headerKey2、headerValue是显示的默认值
3、id是select标签的id,name是select标签的name
4、listkey是request.listinfo中的key,listvalue是request.listinfo的value
vo类:TestForm.java
public class TestForm {
private String id;
private String name;
public TestForm(){};
public TestForm(String id, String name) {
super();
this.id = id;
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
action类 Testajax.java
public class Testajax extends BaseAction implements ModelDriven<TestForm>{
private TestForm testForm;
public TestForm getModel() {
if(testForm == null){
testForm = new TestForm();
}
return testForm;
}
@Override
public String execute() throws Exception {
System.out.println("start-----------------");
List<TestForm> list =new ArrayList<TestForm>();
Map<String,String> map = new HashMap<String, String>();
// list.add("first");
// list.add("second");
// list.add("");
map.put("a", "A");
map.put("b", "B");
map.put("c", "C");
list.add(new TestForm("",""));
System.out.println(list.size());
request.setAttribute("listinfo",list);
request.setAttribute("map", map);
return SUCCESS;
}
}
my.jsp
<script type="text/javascript">
$(document).ready(function(){
$("#infos").change(function(){
alert($("#infos").val());
});
$("#info").change(function(){
alert($("#info").val());
});
});
</script>
</head>
<body>
<s:if test="#request.listinfo != null">
<s:select list="#request.listinfo"
headerKey="000" headerValue="请选择"
id="infos" name="infos"
listKey="id" listValue="name"
>
</s:select>
<s:select list="#request.map"
headerKey="000" headerValue="请选择"
id="info" name="info"
listKey="key" listValue="value"
>
</s:select>
</s:if>
<a href="system/testajax.do">request</a>
</body>
</html>