来自对话框的通知

时间:2012-05-13 22:45:34

标签: jquery jquery-ui

我想在用户按下按钮关闭对话框时收到通知。我尝试了以下但是它没有工作:

<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");
        }
    }
});

还有其他想法吗?

1 个答案:

答案 0 :(得分:1)

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

请参阅此working Fiddle Example!

将代码重写为:

$("#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");
        }
    }
});

请参阅此working Fiddle example!