【问题标题】:Find only current jQueryUI dialog's contents in dialog open handler在对话框打开处理程序中仅查找当前 jQuery UI 对话框内容
【发布时间】:2019-01-19 11:39:36
【问题描述】:

我有一个可以同时打开多个 jQueryUI 对话框的应用程序。

我的问题是我无法弄清楚如何在对话框的打开处理程序中仅找到当前对话框元素。

我尝试了 $(this)、ui、ui.dialog 和其他一些东西,但没有结果。

$("<div class='dialog' title='" + title + "'><p>" + text + "</p></div>")
    .dialog({
        closeOnEscape: false,
        open: function (event, ui) {
            /* 
               What can I use to filter the two selectors below
               so that they only affect the current dialogs contents?
            */
            $(".ui-dialog-titlebar-close", ui.dialog | ui).hide();
            $('.ui-dialog-buttonpane', ui.dialog | ui).find('button').each(function (id, el) {
                /* This cycles through all buttons on all dialogs */
                debugger;
            });
        },
        buttons: {
            "Button 1": function () { doStuff; },
            "Button 2": function () { doStuff; },
            "Button 3": function () { doStuff; }
        }
    });

【问题讨论】:

    标签: jquery-ui-dialog


    【解决方案1】:

    我的解决方案是引用事件目标父元素。

    例如event.target.parentElement

    $("<div class='dialog' title='" + title + "'><p>" + text + "</p></div>")
        .dialog({
            closeOnEscape: false,
            open: function (event, ui) {
                /* Hide the close button of the dialog your are loading */
                $(".ui-dialog-titlebar-close", event.target.parentElement).hide();
    
                /* Cycle through only the buttons belonging to the current dialog */
                $('.ui-dialog-buttonpane', event.target.parentElement).find('button').each(function (id, el) {
                    debugger;
                });
            },
            buttons: {
                "Button 1": function () { doStuff; },
                "Button 2": function () { doStuff; },
                "Button 3": function () { doStuff; }
            }
        });
    

    【讨论】:

      猜你喜欢
      • 2014-08-18
      • 1970-01-01
      • 2012-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多