问题
How to call action on onchange event with select option in struts2.
Here is my code and how can I integrate with On change event.
<s:select name="menuItem" list="menuItems" listKey="menuItemID"
listValue="menuItemName" headerValue="--MenuItems--"
cssClass="selectbox_bg2" id="select" />
Can anyone please provide an example..
Thanks,
回答1:
There is no difference in how you apply onchange
or any other javascript event handler to struts tag as compared to regular HTML tags. Struts2 select Tag Ref
<s:select name="menuItem" list="menuItems" listKey="menuItemID"
listValue="menuItemName" headerValue="--MenuItems--"
cssClass="selectbox_bg2" id="select" onchange="handleChange(this.value)"/>
JavaScript
function handleChange(value){
window.location="callMyAction?ValueToSubmit="+value; //or you can submit a form from here or make an ajax call
}
Or if you are using jquery then
$("#select").change(function(e){
var value = $(this).val();
//submit a form or make ajax call or use window.location
});
来源:https://stackoverflow.com/questions/12948226/onchange-event-in-struts2