C# 如何在单击按钮后禁用按钮两秒钟,然后再次启用按钮本身?

C# 如何在单击按钮后禁用按钮两秒钟,然后再次启用按钮本身?,c#,javascript,asp.net,C#,Javascript,Asp.net,如何在单击按钮后禁用按钮两秒钟,然后再次启用按钮本身 我想在javascript中的OnClientClick中执行此操作,在运行OnClientClick之后,它将运行OnClick事件,然后再次启用按钮。在纯javascript中执行此操作非常简单: var btn = document.getElementById("myButton"); btn.onclick = function() { btn.disabled = true; // disable button w

如何在单击按钮后禁用按钮两秒钟,然后再次启用按钮本身


我想在javascript中的OnClientClick中执行此操作,在运行OnClientClick之后,它将运行OnClick事件,然后再次启用按钮。在纯javascript中执行此操作非常简单:

var btn = document.getElementById("myButton");
btn.onclick = function() {
    btn.disabled = true; // disable button
    window.setTimeout(function() {
       btn.disabled = false; // enable button
    }, 2000 /* 2 sec */); 
}; // Warning: this will replace existing onclick event
如果正在使用,则可以使用以下代码:

var btn = $("#myButton");
btn.click(function() {
    btn.attr("disabled", "disabled"); // disable button
    window.setTimeout(function() {
       btn.removeAttr("disabled"); // enable button
    }, 2000 /* 2 sec */); 
});

您可以使用此功能:

//Disable the button here
setTimeout("EnableTheButton();", 2000); // put this inside the click event
function EnableTheButton() {
    // enable the button here
}
然后声明此函数:

//Disable the button here
setTimeout("EnableTheButton();", 2000); // put this inside the click event
function EnableTheButton() {
    // enable the button here
}

使用“均匀单击”禁用按钮,然后设置超时以在所需时间后重新启用:

<button onclick="
  var button = this;
  this.disabled = true;

  // Put other listener code here

  window.setTimeout(function(){
    button.disabled = false;
  }, 2000);
">Button</button>
试试这个: HTML页面:

<button id="myButon" onclick="disableButon();"></button>
下一个功能启用:

function activateButon()
{
    document.getElementById('myButon').disabled = false;
}

请参阅下面的代码片段,以在10000毫秒(10秒)后启用保存按钮

最初可以将控件设置为disabled:true或OnLoad,您可以设置disabled(true)。这完全符合你的要求。然后,您可以通过以下方式进行操作:

clearTimeout(此.enableSave按钮)

this.enableSaveButton=setTimeout(函数(){

if(Ext.getCmp('btn-Save'))

Ext.getCmp('btn-Save').setDisabled(false);

},10000)