如何在點擊後禁用按鈕兩秒鐘,然後再次啓用自己?如何在點擊後禁用按鈕兩秒,然後再次啓用自己?
我想這樣做在的OnClientClick JavaScript和後運行的OnClientClick它將運行OnClick事件後,再次啓用按鈕
如何在點擊後禁用按鈕兩秒鐘,然後再次啓用自己?如何在點擊後禁用按鈕兩秒,然後再次啓用自己?
我想這樣做在的OnClientClick JavaScript和後運行的OnClientClick它將運行OnClick事件後,再次啓用按鈕
您可以使用此功能:
//Disable the button here
setTimeout("EnableTheButton();", 2000); // put this inside the click event
然後聲明此功能:
function EnableTheButton() {
// enable the button here
}
要在純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
如果你使用jQuery,那麼你可以使用此代碼來代替:
var btn = $("#myButton");
btn.click(function() {
btn.attr("disabled", "disabled"); // disable button
window.setTimeout(function() {
btn.removeAttr("disabled"); // enable button
}, 2000 /* 2 sec */);
});
使用點擊甚至禁用按鈕,然後設置超時所需的時間後重新啓用它:
<button onclick="
var button = this;
this.disabled = true;
// Put other listener code here
window.setTimeout(function(){
button.disabled = false;
}, 2000);
">Button</button>
或動態附:
window.onload = function() {
document.getElementById('b0').onclick = function() {
var button = this;
button.disabled = true;
// Put other listener code here
window.setTimeout(function(){
button.disabled = false;
}, 2000);
};
}
試試這個: HTML頁面:
<button id="myButon" onclick="disableButon();"></button>
JavaScript部分:
function disableButon()
{
var timer;
document.getElementById('myButon').disabled = true;
timer = setTimeout("activateButon()", minutes * 60000);
}
下一頁功能使能:
function activateButon()
{
document.getElementById('myButon').disabled = false;
}
請參考下面的代碼片段對於後10000毫秒啓用保存按鈕(10秒)
You ca n最初將您的控件設置爲禁用:true或OnLoad,您可以設置禁用(true)。這絕對是你的要求。然後,你可以做以下的方法:
clearTimeout(this.enableSaveButton);
this.enableSaveButton = setTimeout(function() {
if (Ext.getCmp('btn-Save'))
Ext.getCmp('btn-Save').setDisabled(false);
}, 10000);
請注意,此代碼僅適用於ExtJs – 2014-09-09 10:12:23
http://stackoverflow.com/questions/10471964/how-can-i-disable -all-the-submit-buttons-then-re-enable-specific-ones – Rakesh 2013-03-21 05:49:23