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

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

如何在jquery中提交表單之前區分兩次特定的點擊?

如何在jquery中提交表單之前區分兩次特定的點擊?

湖上湖 2023-12-25 16:19:18
我有兩個事件,第一個事件用于添加新元素,第二個事件用于編輯元素。如果不提交表格,我不確定如何區分它們。我需要以前的事件,以便我可以在提交事件中使用它們。由于添加和編輯有一些相同的條件,所以我沒有將它們保存在單獨的文件中。但對于某些條件,我必須指定這些是否適用于“添加”事件或“編輯”事件,我似乎找不到任何方法。這是我的代碼:$('.addButton').on('click',function(){   //console.log('add event');   $('#forTest').modal('toggle');});  //after trigerring this will go to the below submit code$('#submitForm').on('click',function () {   // some conditions    /* where condition is same except the error message are different like for      add : this message : values are empty      edit: this message : same values are there   */  $('#test_form').submit();});  $('.edit-button'.on('click', function(){  $('#forTest').modal('toggle');  //edit button which will trigger to upper submit form});
查看完整描述

1 回答

?
泛舟湖上清波郎朗

TA貢獻1818條經驗 獲得超3個贊

使用變量,例如。action并在不同的點擊監聽器中設置不同的值:


let action;


$('.addButton').on('click',function(){

   action = "add";

   $('#forTest').modal('toggle');

});  


$('.edit-button'.on('click', function(){

    action = "edit";

    $('#forTest').modal('toggle');  //edit button which will trigger to upper submit form

});


$('#submitForm').on('click',function () {


  if(action === "edit"){ /* Edit code */}

  else{ /* Add code */ }


  $('#test_form').submit();

}); 


查看完整回答
反對 回復 2023-12-25
  • 1 回答
  • 0 關注
  • 147 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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