当此对话框动态加载页面时,如何加载Dialog JQuery UI两次?

时间:2022-12-01 16:17:06

I have this code:

我有这个代码:

 $(function(){

          $('#dialog').dialog({
              autoOpen: false,
              closeOnEscape: false,
              modal: true,
              width: 450,
              buttons: {
                  "Enviar": function() {
                      $('#new_message').submit();
                  }
              }
          });

          $('#dialog_link').click(function(){
              $('#dialog').load('/messages/new');
              $('#dialog').dialog("open");
          });

      });

When I click in the in first time, the Dialog open, but, in the second time it did not open, and I know that the problem is when a use the .load method, when I comment this code, the Dialog always open when I click in the link.

当我在第一次单击时,对话框打开,但是,在第二次它没有打开时,我知道问题是当使用.load方法时,当我评论此代码时,Dialog总是打开时我点击链接。

How to fix it?

怎么解决?

ps: I'm using with Rails 3.

ps:我正在使用Rails 3。

1 个解决方案

#1


0  

Because of the very bizarre behaviour of jQuery dialogs, here's how I've found it's best to handle this situation:

由于jQuery对话框的非常奇怪的行为,这里是我发现它最好处理这种情况:

I build my HTML like this:

我像这样构建我的HTML:

<div id="myDialog">
</div>

... dynamically loaded HTML comes in a <div class="clearOnClose"></div> container

And then my javascript:

然后我的javascript:

var myDialog = $('#myDialog');

...

if (myDialog.is('.ui-dialog-content')) {
    myDialog.dialog('open');
} else {
    myDialog.dialog({ modal: true, position: [200, 100], close: clearOnClose, etc. other options... });
}

...

// need to call on dialogs to make sure they don't interfere with each other
var clearOnClose = function (event, ui) {
    jQuery(this).find('div.clearOnClose').html('');
};

#1


0  

Because of the very bizarre behaviour of jQuery dialogs, here's how I've found it's best to handle this situation:

由于jQuery对话框的非常奇怪的行为,这里是我发现它最好处理这种情况:

I build my HTML like this:

我像这样构建我的HTML:

<div id="myDialog">
</div>

... dynamically loaded HTML comes in a <div class="clearOnClose"></div> container

And then my javascript:

然后我的javascript:

var myDialog = $('#myDialog');

...

if (myDialog.is('.ui-dialog-content')) {
    myDialog.dialog('open');
} else {
    myDialog.dialog({ modal: true, position: [200, 100], close: clearOnClose, etc. other options... });
}

...

// need to call on dialogs to make sure they don't interfere with each other
var clearOnClose = function (event, ui) {
    jQuery(this).find('div.clearOnClose').html('');
};