简体   繁体   中英

jQuery UI Dialog opens only once

I found answer to this questions on SO but it seems that the problem is different here. I cannot open it again after it has been closed.

EDIT: Ok, seems that there are errors in my Jquery code elsewhere.

 $(function() {
    $( "#dialog" ).dialog({
        autoOpen: false,
        show: "blind",
        hide: "explode"
    });
  $('#opener').click(openDialog);

})

var openDialog = function(){


   $('#dialog').dialog('option', 'buttons',{
      "Cancel":function(){
         $('#dialog').dialog('close');
      }
  });


 $('#dialog').dialog('open');

};

And HTML:

<div id="dialog" title="Basic dialog">
    <p>This is an animated dialog which is useful for displaying information. The     dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>

<button id="opener">Open Dialog</button>

It seems to work for me: http://jsfiddle.net/DSNt5/1/

Try to add destroy method call on dialog close:

var openDialog = function(){
   $('#dialog').dialog('option',
    close: function () { $(this).dialog("destroy"); },
    'buttons',{
      "Cancel":function(){
         $('#dialog').dialog('close');
      }
  });

Have a look at this jsFiddle as it works

edits: updated link as it wasn't the one

I think you should use hide instead of close in

$('#dialog').dialog('option', 'buttons',{
  "Cancel":function(){
     // notice the hide here
     $('#dialog').dialog('hide');
  }
});

i haven't tested it but, as far as i can remember it. hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM