我有一個功能,可以在asp.net中進行一些數據庫更新。我想要一個模式彈出窗口,在我的函數被調用5秒後顯示「成功」消息。在這種情況下,模式彈出窗口不會被任何「TargetControl」觸發,但一旦完成該功能,只會顯示5秒鐘。如何計時模式彈出?
感謝
我有一個功能,可以在asp.net中進行一些數據庫更新。我想要一個模式彈出窗口,在我的函數被調用5秒後顯示「成功」消息。在這種情況下,模式彈出窗口不會被任何「TargetControl」觸發,但一旦完成該功能,只會顯示5秒鐘。如何計時模式彈出?
感謝
不能接近標準的JavaScript模態對話框(警告,確認,..)在超時後。只有手動關閉與他們合作。
但是,你可以使用jquery/UI dialog:
// timeOut in ms
function showMessageWithTiemout(message, timeOut){
// show dialog
var successDialog = $('<div>'+message+'</div>').dialog({modal: true});
//close it after 5 seconds
setTimeout(function(){ successDialog.dialog('close'); }, timeOut);
}
//usage:
showMessageWithTiemout('success!', 5000);
您必須手動調用諸如面板上的顯示方法:
var pnl = $find("<%= modal.ClientID");
pnl.show();
所以,你可以使用window.setTimeout調用這個:
window.setTimeout(function() { /* code */ }, 5000);
但它不能只是發生很容易。
HTH。
你在說AjaxControlToolkit Modal Popup嗎? – 2011-04-14 17:11:12
「失敗」消息彈出持續時間需要多長時間? – 2011-04-14 18:56:40
@Brian - 是的,我指的是AjaxControlToolkit Modal Popup。 – 2011-04-16 07:58:09