0

我想在用户按下按钮关闭对话框时收到通知。我尝试了以下方法,但它不起作用:

<div id="TestDialog"/>

$("#TestDialog").dialog({
    autoOpen: true,
    resizable: true,
    modal: true,
    position: ['middle', 'middle'],
    savePushed: function() {
        alert('save pushed');
    },
    closePushed: function() {
        alert('save pushed');
    },

    buttons: {
        "Save": function() {
            // alert('save');
            savePushed();

            $(this).dialog("close");
        },
        Close: function() {
            //alert('close');
            closePushed();
            $(this).dialog("close");
        }
    }
});

还有其他想法吗?

4

1 回答 1

1

您必须正确定义savePushed()andclosePushed()函数。由于它们不是Jquery-UI Dialog的一部分,因此您不能将其设置为它的选项。

请参阅此工作小提琴示例!

将您的代码重写为:

$("#TestDialog").dialog({
    autoOpen: true,
    resizable: true,
    modal: true,
    position: ['middle', 'middle'],
    buttons: {
        "Save": function() {
            alert('Save button was pressed!');
            $(this).dialog("close");
        },
        "Close": function() {
            alert('Close button was pressed!');
            $(this).dialog("close");
        }
    }
});

如果你需要

调用该函数,savePushed()或者closePushed(),当用户按下按钮时,您可以将代码重写为:

function savePushed() {
    alert('Save button was pressed!');
}

function closePushed() {
    alert('Save button was pressed!');
}

$("#TestDialog").dialog({
    autoOpen: true,
    resizable: true,
    modal: true,
    position: ['middle', 'middle'],
    buttons: {
        "Save": function() {
            savePushed();
            $(this).dialog("close");
        },
        "Close": function() {
            closePushed();
            $(this).dialog("close");
        }
    }
});

请参阅这个工作小提琴示例!

于 2012-05-13T22:50:28.960 回答