jQuery UI Dialog Box - does not open after being c

2020-01-26 03:17发布

I have a problem with the jquery-ui dialog box.

The problem is that when I close the dialog box and then I click on the link that triggers it, it does not pop-up again unless I refresh the page.

How can I call the dialog box back without refreshing the actual page.

Below is my code:

$(document).ready(function() {
    $('#showTerms').click(function()
    {
        $('#terms').css('display','inline');
        $('#terms').dialog({
            resizable: false,
            modal: true,
            width: 400,
            height: 450,
            overlay: { backgroundColor: "#000", opacity: 0.5 },
            buttons:{ "Close": function() { $(this).dialog("close"); } },
            close: function(ev, ui) { $(this).remove(); },
    }); 
});

Thanks

12条回答
The star\"
2楼-- · 2020-01-26 03:52
$(this).dialog('destroy');

works!

查看更多
我命由我不由天
3楼-- · 2020-01-26 03:54

You're actually supposed to use $("#terms").dialog({ autoOpen: false }); to initialize it. Then you can use $('#terms').dialog('open'); to open the dialog, and $('#terms').dialog('close'); to close it.

查看更多
小情绪 Triste *
4楼-- · 2020-01-26 04:02

on the last line, don't use $(this).remove() use $(this).hide() instead.

EDIT: To clarify,on the close click event you're removing the #terms div from the DOM which is why its not coming back. You just need to hide it instead.

查看更多
放荡不羁爱自由
5楼-- · 2020-01-26 04:02

I use the dialog as an dialog file browser and uploader then I rewrite the code like this

var dialog1 = $("#dialog").dialog({ 
              autoOpen: false, 
              height: 480, 
              width: 640 
}); 
$('#tikla').click(function() {  
    dialog1.load('./browser.php').dialog('open');
});   

everything seems to work great.

查看更多
混吃等死
6楼-- · 2020-01-26 04:03

Hi Guys I managed to solve it.

I used destroy instead close function (It doesn't make any sense) but it worked!

$(document).ready(function() {
$('#showTerms').click(function()
{
    $('#terms').css('display','inline');
    $('#terms').dialog({resizable: false,
        modal: true,
        width: 400,
        height: 450,
        overlay: { backgroundColor: "#000", opacity: 0.5 },
        buttons:{ "Close": function() { $(this).dialog('**destroy**'); } },
        close: function(ev, ui) { $(this).close(); },
    });         
});   
$('#form1 input#calendarTEST').datepicker({ dateFormat: 'MM d, yy' });
});
查看更多
Ridiculous、
7楼-- · 2020-01-26 04:03

.close() is mor general and can be used in reference to more objects. .dialog('close') can only be used with dialogs

查看更多
登录 后发表回答