jQuery's one() will fire the attached event handler once for each element bound, and then remove the event handler.
If for some reason that doesn't fulfill the requirements, one could also disable the button entirely after it has been clicked.
$(document).ready(function () {
$("#submit").one('click', function (event) {
event.preventDefault();
//do something
$(this).prop('disabled', true);
});
});
It should be noted that using the ID submit
can cause issues, as it overwrites the form.submit
function with a reference to that element.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…