2011-04-28 74 views
0

我有一個asp.net頁面,當用戶單擊保存按鈕時,數據庫在代碼隱藏中更新。保存完記錄後,我希望顯示固定秒數(例如5)的消息或對話框,然後讓它消失。或者如果用戶點擊它,它會消失。然後把它們留在他們所在的同一頁面上。jquery顯示當前對話框

謝謝。

+1

那麼問題出在哪裏? – Bakudan 2011-04-28 16:13:22

+0

尋找在谷歌jQuery的彩盒,你會得到你所需要的,我猜。 – Bene 2011-04-28 16:15:22

回答

0

看看這個樣品,也許這將有助於:

if (condition == true) { 
//Widen the scope of the myTimer variable 
    var myTimer; 

//Open a jQuery dialog, requires the jQueryUI 
//Create the dialog on the fly 
    $('<div id="myDialog"></div>').html('<p>Your content was saved!</p>').dialog({ 
    'width' : 200, 
    'height' : 100, 
    'modal' : true, 
    'open' : function() { 
    //Set a timer which will automatically close the dialog in 5 sec 
     myTimer = setTimeout(function() { 
     //Close then remove the dialog 
     $('#myDialog').dialog('close').remove(); 
     }, 5000); //Close in 5000 ms (5 sec) 
    }, 
    'close' : function() { 
    //For extra security, clear the timer when the dialog is closed 
     clearTimeout(myTimer); 
    }, 
    'buttons' : { 
     'Ok' : function() { 
     $(this).dialog('close').remove(); 
     } 
    } 
    //Check out http://docs.jquery.com/UI/Dialog for more customize options 
    }); 
} 

我沒有測試上面的代碼,但它應該工作,如果您自定義它爲您的需求。

希望幫助,
spryno724

+0

謝謝,效果很好。除了如果我拖動或調整大小和時間到期我得到一個錯誤。如果點擊對話框來解除它,我怎麼能做到這一點? – tim 2011-04-28 17:17:58

+0

我設置可調整大小和拖動到false,並擺脫了錯誤。 – tim 2011-04-28 17:25:00

+0

很高興它爲你工作! – 2011-04-28 17:27:47

0

只是回答你的第二個問題,如何使整個對話框消失,如果被點擊的任何部分。只需要添加另外的jQuery塊:

$('#myDialog').live('click', function() { 
//Close the dialog 
    $(this).dialog('close').remove(); 

//Remove the timer 
    clearTimeout(myTimer); 
}); 

同樣,我還沒有測試它,但它應該工作。

只需在上面顯示的另一個較大的jQuery塊之後直接添加上面的塊。

希望幫助,
spryno724

+0

輝煌,謝謝。 – tim 2011-04-28 18:51:33