1 $("form").submit(function () { 2 console.log("提交了"); 3 $("input:submit").attr("disabled", "true"); 4 setTimeout(function () { 5 $("input:submit").removeAttr("disabled"); 6 }, 3000); 7 });
网上看到老外写的
1 // jQuery plugin to prevent double submission of forms 2 jQuery.fn.preventDoubleSubmission = function() { 3 $(this).on('submit', function(e) { 4 var $form = $(this); 5 6 if ($form.data('submitted') === true) { 7 // Previously submitted - don't submit again 8 e.preventDefault(); 9 } else { 10 // Mark it so that the next submit can be ignored 11 $form.data('submitted', true); 12 } 13 }); 14 15 // Keep chainability 16 return this; 17 }; 18 19 20 //Use it like this 21 $('form').preventDoubleSubmission();