我試圖在不刷新頁面的情況下提交表單,我使用這個庫來執行多步表單,但是最后它通過加載到表單操作來強制提交表單,我試圖通過將 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;
});
- 1 回答
- 0 關注
- 90 瀏覽
添加回答
舉報
0/150
提交
取消