从ajax加载的内容元素的事件关闭jQueryUI对话框

时间:2012-11-23 15:00:20

标签: jquery jquery-ui

我使用.load()传递url来加载内容。 在返回并成功加载到jq ui对话框的内容中,是与id cancel123的简单链接。 我只是试图通过点击链接关闭这个jqueryUiDialog w ID testDialog。 我无法弄清楚我失踪了什么,并尝试以48种不同的方式做到这一点。请帮忙

 function InitializeDialog($element, title, url) {

            $element.dialog({
                autoOpen: false,
                width: 500,
                resizable: true,
                draggable: true,
                title: title,
                model: true,
                show: 'slide',
                closeText: 'x',
                //dialogClass: 'alert',
                closeOnEscape: true,
                modal: true,
                open: function (event, ui) {
                    //Load the Partial View Here using Controller and Action
                    $element.load(url);
                    $("#cancel123").bind('click', function (event) {
                        $('#testDialog').dialog('close');
                        alert('close this');
                    });


                },

                close: function () {
                    $(this).dialog('close');
                }
            });

1 个答案:

答案 0 :(得分:2)

您可以将其绑定到文档,如下所示:

$(document).on("click", "#cancel123", function(event) {
    $('#testDialog').dialog('close');
    alert('close this');
});

另一种方式(我认为它更好):

$element.load(url, function() {
    $("#cancel123").bind('click', function (event) {
        $('#testDialog').dialog('close');
        alert('close this');
    });
});
相关问题