问题
I have the following piece of code :
<sx:datetimepicker name="dateOfBirth" id="dateOfBirth"
displayWeeks="5" displayFormat="dd/MM/yyyy" onchange="test()"/>
But for this the onchange event does not work althought i have a simple javascript function like this :
<script>
function test(){
alert('hi-----');
}
</script>
Note: I read somewhere that it is a bug in struts that the onChange event doesnt work for dateTimePicker. However I am not sure about it. Is there any workaround discovered for it?
回答1:
Dojo tags are deprecated. Use jQuery tags. You can find more about struts2-jquery-plugin. You should use datepiker tag.
<%@ taglib prefix="sj" uri="/struts-jquery-tags" %>
<head>
<link href="<s:url value="/css/template_styles.css"/>" type="text/css" rel="stylesheet">
<sj:head jqueryui="true" />
<title></title>
</head>
<script type="text/javascript">
$.subscribe('changeTopic', function(event,data) {
alert('Date : '+event.originalEvent.dateText);
});
</script>
<sj:datepicker name="dateOfBirth" id="dateOfBirth" label="DOB" displayFormat="dd/MM/yy" onChangeTopics="changeTopic"/>
来源:https://stackoverflow.com/questions/25159250/onchange-does-not-work-for-datetimepicker-in-struts2