开发者

Limit button clicks to once every 5 minutes [duplicate]

This question already has answers here: Closed 11 years ago.

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);
    }; 
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜