亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

form.submit() 將在表單內觸發 double

form.submit() 將在表單內觸發 double

倚天杖 2023-02-23 16:08:39
再會,以下是我的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]任何人都知道代碼有什么問題?
查看完整描述

1 回答

?
MMTTMM

TA貢獻1869條經驗 獲得超4個贊

如果在提交表格之前要檢查確認,則必須使用表格中的<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您可以通過對元素執行操作來訪問元素的形式


查看完整回答
反對 回復 2023-02-23
  • 1 回答
  • 0 關注
  • 125 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號