禁止form重复提交

mac2022-06-30  25

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();

 

转载于:https://www.cnblogs.com/qzsonline/p/3178247.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)