开发者

jquery dialog best approach [closed]

开发者 https://www.devze.com 2023-04-08 15:20 出处:网络
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references,or expertise, but this question will likely solicit debate, a
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 11 years ago.

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 );
0

精彩评论

暂无评论...
验证码 换一张
取 消