disable an Asp.net Button then enable it after 5 s

2019-02-25 14:11发布

I want to run an Asp.net button click event (After clicking it) then disable it for 5 seconds and enable it again. I use this java script code but the click event code does not executed. What is wrong with it? I am new with js.

 function lockoutSubmit(button) {
        var oldValue = button.value;

        button.setAttribute('disabled', true);
        button.value = 'Wait 5 sec';

        setTimeout(function () {
            button.value = oldValue;
            button.removeAttribute('disabled');
        }, 5000)
  }

html:

 <asp:Button ID="Button1" 
                runat="server" 
                Text="Send" 
                onclientclick="lockoutSubmit(this)" />

2条回答
叼着烟拽天下
2楼-- · 2019-02-25 14:56

You can try this:

function lockoutSubmit(button) {
    var oldValue = button.value;

    setTimeout(function () {
        button.setAttribute('disabled', true);
        button.value = 'Wait 5 sec';
    }, 0);

    setTimeout(function () {
        button.value = oldValue;
        button.removeAttribute('disabled');
    }, 5000);
}
查看更多
叛逆
3楼-- · 2019-02-25 15:07

check this out. https://jsfiddle.net/9ds9mL1v/5/

$("#Button1").click(function(){
var button =$(this);
  var oldValue = $(this).value;

    button.attr('disabled', true);
    button.value = 'Wait 5 sec';

    setTimeout(function () {
        button.value = oldValue;
        button.removeAttr('disabled');
    }, 5000)


});
查看更多
登录 后发表回答