0
$(function () {
        $('#modalDlg2').live("click", function (event) {
            event.preventDefault();
            loadDialog(event, "/User/Create");
        });
        function loadDialog(event, target) {
            var $dialog = $('<div></div>');
            $dialog.empty();
            $dialog
    .load(target)
    .dialog({
    title:"Novo utilizador",
        modal: true,
        autoOpen: false,
        width: 600,
        show:'fade',
        hide:'fade',
        minHeight: 400,
        resizable: false
    });

     $dialog.dialog( "option", "buttons", {
            "Cancelar": function() { 
                    $(this).dialog("close");
                    $(this).empty();
                }         });
            $dialog.dialog('open');
        }            
    })

我的关闭按钮“Cancelar”有问题,它应该关闭模式对话框然后清空它,但似乎 $(this).dialog("close") 不起作用,而 .empty() 起作用。
我一直在寻找我的问题的解决方案。谁能帮我解决这个问题?

4

3 回答 3

0

我会尝试将其放入负载的回调函数中:

$(function() {
    $('#modalDlg2').on("click", function(event) {
        event.preventDefault();
        loadDialog(event, "/User/Create");
    });

    function loadDialog(event, target) {
        var $dialog = $('<div></div>');
        $dialog.empty();
        $dialog.load(target, function() {
            $dialog.dialog({
                title: "Novo utilizador",
                modal: true,
                autoOpen: false,
                width: 600,
                show: 'fade',
                hide: 'fade',
                minHeight: 400,
                resizable: false
            });

            $dialog.dialog("option", "buttons", {
                "Cancelar": function() {
                    $(this).dialog("close");
                    $(this).empty();
                }
            });
            $dialog.dialog('open');
        });
});
于 2012-11-13T14:43:12.803 回答
0

试试这个:

$dialog.dialog( "option", "buttons", {
    "Cancelar": function() { 
            $dialog.dialog("close");
            $(this).empty();
    }
});
$dialog.dialog('open');

或者

$dialog.dialog( "option", "buttons", {
   "Cancelar": $.proxy(function() { 
        $(this).dialog("close");
        $(this).empty();
    },this)         
});
$dialog.dialog('open');
于 2012-11-13T14:45:03.380 回答
0

试试下面的代码:

$dialog.dialog("option", "buttons", { "Cancelar": function() { $(this).remove(); } });
于 2014-08-08T06:00:15.873 回答