form.submit() 将在表单内触发 double

再会,


以下是我的jsp代码:


<s:form beanclass="c.c.i.c.app.profile.ui.ChangePasswordAction" method="post" name="form1">

<!-- some others code here -->

     <sx:row cssClass="button_row">

          <sx:input name="updatePassword" image="submit"/>  

     </sx:row>

</s:form>

这是我的jquery:


<script type="text/javascript">

$(':input[name=updatePassword]').click(function() {


        var answerProceed = confirm("Do you wish to proceed with the changes?");


        if( answerProceed ){

            var form = $("form[name=form1]");

            form.attr("action", '<s:url beanclass="c.c.i.c.app.profile.ui.ChangePasswordAction" event="update"/>');

            form.submit();

        } else {

        return false;}

    });

</script>

我们可以看到,在 jQuery 中,它会触发一个update事件到ChangePasswordAction.


但是,目前我有一个问题,就是有时候会触发2次,不是每次都会发生,但是发生率在50%左右。


以下是我从我的应用程序日志中得到的触发日志:


2019-06-26 18:19:13.658 [WebContainer : 31] TRACE o.s.w.c.s.XmlWebApplicationContext - [bmaker] - Publishing event in Root WebApplicationContext: org.springframework.security.event.authorization.AuthorizedEvent[source=FilterInvocation: URL: /common/change_password.html?update=&__stoken=1a47d3a9-29e8-4904-b204-3cb9fc0129f0]

2019-06-26 18:19:13.660 [WebContainer : 26] TRACE o.s.w.c.s.XmlWebApplicationContext - [bmaker] - Publishing event in Root WebApplicationContext: org.springframework.security.event.authorization.AuthorizedEvent[source=FilterInvocation: URL: /common/change_password.html?update=&__stoken=1a47d3a9-29e8-4904-b204-3cb9fc0129f0]

任何人都知道代码有什么问题?


倚天杖
浏览 115回答 1
1回答

MMTTMM

如果在提交表格之前要检查确认,则必须使用表格中的<input/>is of 。在这种情况下,您可以在侦听器中将 as 参数作为实现参数传递(由于单击事件)。type="submit"preventDefault()eEventMouseEvent例如 :$(':input[name=updatePassword]').click(function(e) { // <-- e implements Event    e.preventDefault(); // <-- prevent the submit of the form    var answerProceed = confirm("Do you wish to proceed with the changes?");    if (answerProceed) {        var form = $("form[name=form1]");        // var form = e.currentTarget.form; you can do this        // var form = this.form; or you can do this, "this" is implicit clicked element        form.attr("action", '<s:url beanclass="c.c.i.c.app.profile.ui.ChangePasswordAction" event="update"/>');        form.submit();    }    else {        return false;    }});.form您可以通过对元素执行操作来访问元素的形式
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java