form 중복 제출 금지

3542 단어 form
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();

좋은 웹페이지 즐겨찾기