加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

JQeury form插件的ajaxForm方法和ajaxSubmit方法的区别

发布时间:2020-12-16 00:31:29 所属栏目:百科 来源:网络整理
导读:/***ajaxForm()providesamechanismforfullyautomatingformsubmission.**TheadvantagesofusingthismethodinsteadofajaxSubmit()are:**1:Thismethodwillincludecoordinatesforinputtype="image"/elements(iftheelement*isusedtosubmittheform).*2.Thismethodwi
/**
*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提交。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读