简体   繁体   English

jQuery UI 对话框仅打开一次

[英]jQuery UI Dialog opens only once

I found answer to this questions on SO but it seems that the problem is different here.我在 SO 上找到了这个问题的答案,但这里的问题似乎有所不同。 I cannot open it again after it has been closed.关闭后我无法再次打开它。

EDIT: Ok, seems that there are errors in my Jquery code elsewhere.编辑:好的,我的 Jquery 代码中似乎有错误。

 $(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:和 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>

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看看这个jsFiddle的工作原理

edits: updated link as it wasn't the one编辑:更新链接,因为它不是那个

I think you should use hide instead of close in我认为你应该使用hide而不是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希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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