Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

enable the button to be clicked only to once exception?

I use a dialog to get the user input, but I found the user may click double click the button and added the content twice, the cause is the dialog fadeout too slow or the user clicked twice on the mouse.. I don't want to adjust the fadeout speed, instead, how to enable the button only can be clicked once?

like image 819
Ulises Colen Avatar asked Sep 27 '13 14:09

Ulises Colen


2 Answers

jQuery provides the one() method to register a one-shot handler that will only run once.

You can write:

$("#yourButton").one("click", function() {
    // Add content...
});
like image 190
Frédéric Hamidi Avatar answered Sep 26 '22 17:09

Frédéric Hamidi


You can disable the button once it was clicked to prevent any further clicks:

$('button').on('click', function() {
    $(this).prop('disabled', true);
});
like image 44
Zathrus Writer Avatar answered Sep 24 '22 17:09

Zathrus Writer