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()および関数を適切に定義する必要がありclosePushed()ます。これらはJquery-UIDialogの一部ではないため、オプションとして設定することはできません。

この実用的なフィドルの例を参照してください!

コードを次のように書き直します。

$("#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 に答える