2

jQuery で SimpleModal を使用しており、確認ダイアログが 1 つあります。結果が の場合、このダイアログYesを呼び出さなければなりません。my.phpただし、コードを作成しましたが、まだアイデアを探しています。どうすればいいですか?

$(document).ready(function () {
    $('#confirmDialog input.confirm, #confirmDialog a.confirm').click(function (e) {
        e.preventDefault();
        // Example of calling the confirm function.
        // You must use a callback function to perform the "yes" action.
        confirm("Continue", function () {
            alert("OK");
        });
    });
});

function confirm(message, callback) {
    $('#confirm').modal({
        close:false,
        position: ["20%",],
        overlayId:'confirmModalOverlay',
        containerId:'confirmModalContainer',
        onShow: function (dialog) {
            dialog.data.find('.message').append(message);

            // If the user clicks "yes"
            dialog.data.find('.yes').click(function () {
                $.get('my.php', function(data){
                    // Create a modal dialog with the data.
                    // Here: How do I write the same window?
                });

                // Call the callback

                // Close the dialog
                $.modal.close();
            });
        }
    });
}

ここで、Ajax の結果から同じウィンドウの Confirmdialog をどのように記述するかという問題があります。どうすればいいですか?

4

2 に答える 2

2

確認機能がニーズに最適かどうかはわかりませんが、次のようなものが機能するはずです。

function confirm(message, callback) {
    $('#confirm').modal({
        close:false,
        position: ["20%",],
        overlayId:'confirmModalOverlay',
        containerId:'confirmModalContainer',
        onShow: function (dialog) {
            dialog.data.find('.message').append(message);

            // If the user clicks "yes"
            dialog.data.find('.yes').click(function () {
                $.get("my.php", function (data) {
                    /* Sample response:
                     *   <div id="title">my title</div>
                     *   <div id="message">my message</div>
                     *
                     */
                    var resp = $("<div/>").append(data);
                    var title = resp.find("#title").html(),
                        message = resp.find("#message").html();

                    dialog.data.find(".header span").html(title);
                    dialog.data.find(".message").html(message);
                    dialog.data.find(".buttons .yes").hide();
                    dialog.data.find(".buttons .no").html("Close");

                    // No need to call the callback or $.modal.close()
                });
            });
        }
    });
}
于 2008-12-28T16:43:02.083 に答える
1

何を達成しようとしているのかよくわかりません -- 確認モーダル ダイアログを再利用して結果を表示しようとしていますか? メッセージの内容を結果に置き換え、ボタンを削除して、コールバックが再度発生しないようにするだけで、ダイアログに「Xを閉じる」ボタンがある場合、これを行うことができると思います。次のようになります。

 dialog.data.find('.message').html( 'new contents from your ajax data' );
 dialog,data.find('.buttons').remove();

ただし、これはモーダル ダイアログの悪用のように思えます。私の意見では、ダイアログにはユーザーとの単一の対話のみを含める必要があります。最初のダイアログの結果に基づいてさらに対話が必要な場合は、現在のダイアログが AJAX の結果で閉じられた後にポップアップする別のモーダル ダイアログを追加するか、AJAX の結果をメイン インターフェイスに挿入して処理することを検討します。そこの。

于 2008-12-27T12:56:20.780 に答える