我在這個環節得到了解決此:
將此代碼放在頭本條
<sj:head jqueryui="true"/>
<script type="text/javascript">
$.subscribe('before', function(event,data) {
var fData = event.originalEvent.formData;
alert('About to submit: \n\n' + fData[0].value + ' to target '+event.originalEvent.options.target+' with timeout '+event.originalEvent.options.timeout);
var form = event.originalEvent.form[0];
if (form.echo.value.length < 2) {
alert('Please enter a value with min 2 characters');
// Cancel Submit comes with 1.8.0
event.originalEvent.options.submit = false;
}
});
$.subscribe('complete', function(event,data) {
alert('status: ' + event.originalEvent.status + '\n\nresponseText: \n' + event.originalEvent.request.responseText +
'\n\nThe output div should have already been updated with the responseText.');
});
$.subscribe('errorState', function(event,data) {
alert('status: ' + event.originalEvent.status + '\n\nrequest status: ' +event.originalEvent.request.status);
});
</script>
而寫的支柱2 jQuery的提交按鈕的事件 -
<div class="type-button">
<sj:submit targets="result"
value="AJAX Submit"
timeout="2500"
indicator="indicator"
onBeforeTopics="before"
onCompleteTopics="complete"
onErrorTopics="errorState"
effect="highlight"
effectOptions="{ color : '#222222' }"
effectDuration="3000"/>
</div>`
但沒有的onsubmit事件在sj:提交按鈕,我檢查了這個[鏈接](http://code.google.com/p/struts2-jquery/wiki/SubmitTag) –
是的我也使用了窗體的onsubmit事件,但我的驗證功能不是調用 –
你確定它永遠不會被調用嗎 - 你可以在裏面放一個alert語句來看它是否觸發? – Fenton