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 probl开发者_如何学Goem is when a use the .load method, when I comment this code, the Dialog always open when I click in the link.
How to fix it?
ps: I'm using with Rails 3.
Because of the very bizarre behaviour of jQuery dialogs, here's how I've found it's best to handle this situation:
I build my HTML like this:
<div id="myDialog">
</div>
... dynamically loaded HTML comes in a <div class="clearOnClose"></div> container
And then my 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('');
};
精彩评论