How to Avoid Double Clicking With jQuery?

-- JQuery 2013. 10. 4. 15:36
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Introduction  

There has been always troubling issue regarding user interaction,when the user Double Clicks the DOM elements. Such as buttons, links etc. Fortunately, jQuery has an awesome solution for this. That is .one() method

 

What does .one Method Do?

It attaches a handler to an event for the elements and that handler is executed at most once per element


 

Example


$("#saveBttn").one("click", function () {
    alert("This will be displayed only once.");
});

OR

 

$("body").one("click", "#saveBttn", function () { 
    alert("This displays if #saveBttn is the first thing clicked in the body.");
});

Key points of the above code:

  • After the code is executed, a click on the element with Id saveBttn will display the alert
  • Subsequent clicks will do nothing
  • This is equivalent to ==>
$("#saveBttn").on("click", function (event) { 
    alert("This will be displayed only once.");
    $(this).off(event);
});

In other words explicitly calling .off() from within a regularly-bound handler has exactly the same effect

출처 : http://www.codeproject.com/Articles/639084/How-to-Avoid-Double-Clicking-With-jQuery

posted by 어린왕자악꿍