javascript - setTimeout("this.disabled=false",3000); is not working - Stack Overflow

I am trying to prevent duplicated data to database when the user click the submit button multiple times

I am trying to prevent duplicated data to database when the user click the submit button multiple times within a very short time (eg double click speed). First I disable the button after one click, then enable the button again after 3 seconds. I don't know why setTimeout("this.disabled=false",3000); is not working on jquery. Please help me out, below is my codes :

$(function() { 
    $(".btnSendResp").click(function() {
        this.disabled = true;
        setTimeout("this.disabled=false",3000);
        postinResp();
    });
});

I am trying to prevent duplicated data to database when the user click the submit button multiple times within a very short time (eg double click speed). First I disable the button after one click, then enable the button again after 3 seconds. I don't know why setTimeout("this.disabled=false",3000); is not working on jquery. Please help me out, below is my codes :

$(function() { 
    $(".btnSendResp").click(function() {
        this.disabled = true;
        setTimeout("this.disabled=false",3000);
        postinResp();
    });
});
Share Improve this question asked May 19, 2011 at 0:27 zac1987zac1987 2,7879 gold badges47 silver badges62 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 16

You have the wrong this.

You need to save a reference to this in a local variable, then pass a function to setTimeout that uses the variable.

For example:

var self = this;
setTimeout(function() { 
    self.disabled = false;
}, 3000);
$(function() { 
    $(".btnSendResp").click(function() {
        var that = this;
        that.disabled = true;
        setTimeout(function(){
            that.disabled=false;
        },3000);
        postinResp();
    });
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743724218a4496338.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信