Close a jQuery UI Dialog from an element inside of it?

荒凉一梦 提交于 2019-12-06 01:29:52

问题


Here's a quick question that's probably simpler than I'm thinking.

I'm populating a jQuery UI dialog with the resulting html from an $.ajax() call. In certain cases that html includes a button that when clicked, I want to close the containing dialog.

Assuming that I don't know anything about the element that was specified to be the dialog using $("#element").dialog()...(i.e. I have no idea what the "#element" selector is from the dialog's inner content) - What's the best way to close the dialog from an element clicked inside of it?


回答1:


Use closest()

$(this).closest('.ui-dialog-content').dialog('close');



回答2:


Something like:

$('a.close').click(function(e) {
    $(this).closest('.dialog').dialog('close');
});


来源:https://stackoverflow.com/questions/2203977/close-a-jquery-ui-dialog-from-an-element-inside-of-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!