我試圖在不刷新頁(yè)面的情況下提交表單,我使用這個(gè)庫(kù)來(lái)執(zhí)行多步表單,但是最后它通過(guò)加載到表單操作來(lái)強(qiáng)制提交表單,我試圖通過(guò)將 form.submit 設(shè)置為來(lái)停止它錯(cuò)誤,但是當(dāng)我這樣做時(shí)它停止發(fā)送請(qǐng)求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貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超5個(gè)贊
使用.submit(或.on)監(jiān)聽(tīng)submitJavaScript 事件。
然后.preventDefault()在事件上取消默認(rèn)行為(提交表單)
$("#myForm").submit(function(e){
e.preventDefault();
return false;
});
- 1 回答
- 0 關(guān)注
- 93 瀏覽
添加回答
舉報(bào)
0/150
提交
取消