从另一个页面加载内容时,jquery对话框不会打开第二个

时间:2022-12-04 17:58:47

I have a jQuery UI dialog which loads content from another page. The dialog opens the first time, but not a second time. If don't load anything into the dialog it works the second time too.

我有一个jQuery UI对话框,可以从另一个页面加载内容。该对话框第一次打开,但不是第二次打开。如果不在对话框中加载任何内容,它也会第二次运行。

See the jsFiddle. [It works, the error must be somewhere else]

看到j​​sFiddle。 [它有效,错误必须在其他地方]

HTML:

HTML:

<a class="click" href="form.php">form</a>
<a class="click" href="data.php">data</a>
<a class="click" href="user.php">user</a>
<div id="dialog"></div>

JavaScript:

JavaScript的:

$(document).ready(function() {
    $("#dialog").dialog({
        autoOpen: false,
        closeOnEscape: true
    });

    $('.click').click(function(event) {
        event.preventDefault();
        $('#dialog').load(this.href);
        $("#dialog").dialog('open');
    });
});​

1 个解决方案

#1


1  

Try opening the dialog in the load's complete callback - the load will run async by default, and so it likely won't be complete by the time you hit the open - that might be what's messing it up (though it's hard to say when the example works :-) )

尝试在加载的完整回调中打开对话框 - 默认情况下加载将运行异步,因此在您打开时可能无法完成 - 这可能是什么搞乱了(虽然很难说什么时候示例有效:-))

var $dialog;
$(document).ready(function() {
  $dialog = $("#dialog").dialog({
    autoOpen: false,
    closeOnEscape: true
  });

  $('.click').click(function(event) {
    event.preventDefault();
    $dialog.load(this.href, function() {
     $dialog.dialog('open');
    });
  });
});​

#1


1  

Try opening the dialog in the load's complete callback - the load will run async by default, and so it likely won't be complete by the time you hit the open - that might be what's messing it up (though it's hard to say when the example works :-) )

尝试在加载的完整回调中打开对话框 - 默认情况下加载将运行异步,因此在您打开时可能无法完成 - 这可能是什么搞乱了(虽然很难说什么时候示例有效:-))

var $dialog;
$(document).ready(function() {
  $dialog = $("#dialog").dialog({
    autoOpen: false,
    closeOnEscape: true
  });

  $('.click').click(function(event) {
    event.preventDefault();
    $dialog.load(this.href, function() {
     $dialog.dialog('open');
    });
  });
});​