Limit button clicks to once every 5 minutes [duplicate]
Possible Duplicate:
jquery disable a button for a specific time
I am using PHP to create a website.
On that website, I would like to have a button that the user can only click once every five minutes.
I have already determined that I will be using jQuery for this scripting, and I know that I will need to set a timeout period of five minutes after the user clicks the button. During this timeout period, the button should not be able to be clicked.
What is the process that I should use to enable this functionality?
开发者_运维技巧Best Regards
You can do it this way. The user can click the button and then when they do, the button is disabled for the next 5 minutes. After 5 minutes it gets re-enabled and the next time it's clicked, it again disables itself for 5 minutes and so on...
$("#go").click(function() {
// no more clicks until timer expires
$(this).attr("disabled", "disabled");
// do whatever you want on the click here
// set timer to re-enable the button
setTimeout(function() {
$("#go").removeAttr("disabled");
}, 5 * 60 * 1000);
});
You can see it work here: http://jsfiddle.net/jfriend00/2scAM/.
hope this will help you
$('#button').attr("disabled", "disabled");
setTimeout('enableButton()', 5000);
function enableButton(){
$('#button').removeAttr('disabled');
}
Try this
Working demo
$(function(){
$("#inputButton").click(buttonClickHanlder);
function buttonClickHanlder(){
//Do you stuff here
alert(this.id);
//Unbind the click event handler, delay 5 mins and then again bind the event handler
$("#inputButton").unbind('click').delay(5 * 60 * 1000).click(buttonClickHanlder);
};
});
精彩评论