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

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

如何通過ajax提交多步驟表單

如何通過ajax提交多步驟表單

PHP
子衿沉夜 2022-10-14 09:58:01
我試圖在不刷新頁面的情況下提交表單,我使用這個庫來執行多步表單,但是最后它通過加載到表單操作來強制提交表單,我試圖通過將 form.submit 設置為來停止它錯誤,但是當我這樣做時它停止發送請求vai ajax。我的 multstepform.js (function ( $ ) {  $.fn.multiStepForm = function(args) {  if(args === null || typeof args !== 'object' || $.isArray(args))    throw  " : Called with Invalid argument";  var form = this;  var tabs = form.find('.containerformtab');  var steps = form.find('.stepform');  steps.each(function(i, e){    $(e).on('click', function(ev){    });  });  form.navigateTo = function (i) {/*index*/    /*Mark the current section with the class 'current'*/    tabs.removeClass('currentform').eq(i).addClass('currentform');    // Show only the navigation buttons that make sense for the current section:    form.find('.previousform').toggle(i > 0);    atTheEnd = i >= tabs.length - 1;    form.find('.nextform').toggle(!atTheEnd);    // console.log('atTheEnd='+atTheEnd);    form.find('.submitform').toggle(atTheEnd);    fixStepIndicator(curIndex());    return form;  }  function curIndex() {    /*Return the current index by looking at which section has the class 'current'*/    return tabs.index(tabs.filter('.currentform'));  }  function fixStepIndicator(n) {    steps.each(function(i, e){      i == n ? $(e).addClass('activeform') : $(e).removeClass('activeform');    });  }  /* Previous button is easy, just go back */  form.find('.previousform').click(function() {    form.navigateTo(curIndex() - 1);  });  /* Next button goes forward iff current block validates */  form.find('.nextform').click(function() {    if('validations' in args && typeof args.validations === 'object' && !$.isArray(args.validations)){      if(!('noValidate' in args) || (typeof args.noValidate === 'boolean' && !args.noValidate)){        form.validate(args.validations);        if(form.valid() == true){          form.navigateTo(curIndex() + 1);          return true;        }        return false;      }    }    form.navigateTo(curIndex() + 1);  });
查看完整描述

1 回答

?
翻閱古今

TA貢獻1780條經驗 獲得超5個贊

使用.submit(或.on)監聽submitJavaScript 事件。


然后.preventDefault()在事件上取消默認行為(提交表單)


$("#myForm").submit(function(e){

    e.preventDefault();

    return false;

});


查看完整回答
反對 回復 2022-10-14
  • 1 回答
  • 0 關注
  • 90 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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