在对话框打开处理程序中仅查找当前 jQuery UI 对话框内容
Find only current jQueryUI dialog's contents in dialog open handler
我有一个可以同时打开多个 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; }
}
});
我的解决方案是引用事件目标父元素。
例如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; }
}
});
我有一个可以同时打开多个 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; }
}
});
我的解决方案是引用事件目标父元素。
例如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; }
}
});