jquery display momentary dialog
I have an asp.net page and when the user click开发者_如何转开发s the Save button the database is updated in code-behind. After I have saved the record I would like to display a message or dialog for a fixed number of seconds (e.g. 5) and then have it go away. Or if the user clicks it have it go away. And then just leave them on the same page where they were.
Thanks.
Take a look at this sample and maybe it will help:
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
});
}
I didn't test the above code, but it should work, if you customize it for your needs.
Hope that helps,
spryno724
Just answering your second question, how to make the whole dialog disappear if any part of it is clicked. Just add another jQuery block:
$('#myDialog').live('click', function() {
//Close the dialog
$(this).dialog('close').remove();
//Remove the timer
clearTimeout(myTimer);
});
Again, I haven't tested it, but it should work.
Just add the above block directly after the other, larger jQuery block I showed above.
Hope that helps,
spryno724
精彩评论