gpt4 book ai didi

当我使用 struts 2 jquery 提交按钮 onClick 事件时,Javascript 验证不起作用

转载 作者:行者123 更新时间:2023-11-28 02:37:18 25 4
gpt4 key购买 nike

我正在使用 struts2-jquery-plugin-3.2.1 。我正在使用它的提交按钮,我在 onclick 事件上调用 javascript 验证,但即使验证未完成,我的表单仍在提交。以下是代码:

<sj:submit
value="Add"
targets="idRightMainDiv"
button="true"
buttonIcon="ui-icon-gear"
formIds="addExerDetailsForm"
onclick="return SetsRepsFormValidate()" //calling javascript validation
tabindex="7"/>

function SetsRepsFormValidate() {
var summary = "";
summary += isSets();
summary += isReps();

if (summary != "") {
dhtmlx.alert(summary);
return false;
}

else {
return true;
}
}

最佳答案

我在此链接中找到了解决方案:

将此代码放在头部-

  <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>

并编写了struts 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>`

关于当我使用 struts 2 jquery 提交按钮 onClick 事件时,Javascript 验证不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13286959/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com