(function( $ ){ $.fn.ajaxform = function(options) { var defualts = { //提交按钮 'submitBtn':'#submit', //method 'method':'POST', //返回信息的容器 'returnInfoBox':'', //加载时按钮上显示的文字 'loadingText':'Submit...', //ajax url 'url':'' }; var opts = $.extend({}, defualts, options); var form = $(this); //this.each(function() { if(opts.submitBtn=='' || opts.url=='') { return false; } var savebtn = opts.submitBtn; var reinfo = opts.returnInfoBox; var btn = $(savebtn).html(); if(opts.returnInfoBox == '') { $(this).append('
'); reinfo = opts.form + ' .ajax-return-info-box'; } $(opts.submitBtn).bind('click', function() { $.ajax({ 'type':"POST", 'url':opts.url, 'data':form.serialize(), 'success':function(html){ $(savebtn).html(btn); $(reinfo).html(html); setTimeout("$('"+savebtn+"').removeAttr('disabled');$('"+reinfo+"').html('')",3000); }, 'beforeSend':function(){ $(savebtn).attr('disabled','disabled'); $(savebtn).html(opts.loadingText); } }); }); //}); }; })( jQuery );