/** *ajaxForm()providesamechanismforfullyautomatingformsubmission. * *TheadvantagesofusingthismethodinsteadofajaxSubmit()are: * *1:Thismethodwillincludecoordinatesfor<inputtype="image"/>elements(iftheelement *isusedtosubmittheform). *2.Thismethodwillincludethesubmitelement'sname/valuedata(fortheelementthatwas *usedtosubmittheform). *3.Thismethodbindsthesubmit()methodtotheformforyou. * *TheoptionsargumentforajaxFormworksexactlyasitdoesforajaxSubmit.ajaxFormmerely *passestheoptionsargumentalongafterproperlybindingeventsforsubmitelementsand *theformitself. */ $.fn.ajaxForm=function(options){ options=options||{}; options.delegation=options.delegation&&$.isFunction($.fn.on); //injQuery1.3+wecanfixmistakeswiththereadystate if(!options.delegation&&this.length===0){ varo={s:this.selector,c:this.context}; if(!$.isReady&&o.s){ log('DOMnotready,queuingajaxForm'); $(function(){ $(o.s,o.c).ajaxForm(options); }); returnthis; } //isyourDOMready?http://docs.jquery.com/Tutorials:Introducing_$(document).ready() log('terminating;zeroelementsfoundbyselector'+($.isReady?'':'(DOMnotready)')); returnthis; } if(options.delegation){ $(document) .off('submit.form-plugin',this.selector,doAjaxSubmit) .off('click.form-plugin',captureSubmittingElement) .on('submit.form-plugin',options,doAjaxSubmit) .on('click.form-plugin',captureSubmittingElement); returnthis; } returnthis.ajaxFormUnbind() .bind('submit.form-plugin',doAjaxSubmit) .bind('click.form-plugin',captureSubmittingElement); };
上面摘录的代码,是JQuery fom插件中ajaxFom这个方法的源代码。
下载地址为:http://plugins.jquery.com/form/
ajaxForm注释的含义,大致强调这点意思:
用ajaxform,要么form表单中包含可以submit的元素,要么方法在注册submit事件中调用。也就是说,用ajaxForm必须要有触发submit的方法,否则无法提交form。
相比而言,ajaxSubmit这个方法将直接触发form的submit提交。
原文链接:https://www.f2er.com/ajax/164800.html