My scenario is: 1. I have 开发者_StackOverflow中文版a link in my page that opens a dialog. 2. Inside this dialog may have another link that opens another dialog, and so on..
What is the best approach to resolve this problem? Where this dialogs will be created?
--
I tried this:
In my page I declare a div to be the placeholder of all my dialogs:
<div id="dialog-placeholder">
</div>
And in my javascript code done something like this:
$(".bs-icon").live("click", function () {
var dp = $("#dialog-placeholder");
dp.html("<div id='dialog'></div>");
//load index page in dialog
$.get("/Car/IndexLookup", function (response) {
dp.find("#dialog").html(response);
var dialog = dp.find("#dialog").dialog({
modal: true,
width: 700,
height: 400,
close: function (ev, ui) { $(this).remove(); }
});
});
});
For now, only one dialog will have focus.
This works, but it is a good way?
You can define if you want your dialog to stack or not on other dialogs. So, you get to decide which dialog you see when multiple dialogs are called.
(from the docs)
dialog option: stack
Specifies whether the dialog will stack on top of other dialogs. This will cause the dialog to move to the front of other dialogs when it gains focus. Code examples Initialize a dialog with the stack option specified.
$( ".selector" ).dialog({ stack: false });
Get or set the stack option, after init.
//getter
var stack = $( ".selector" ).dialog( "option", "stack" );
//setter
$( ".selector" ).dialog( "option", "stack", false );
精彩评论