jQuery 中的简单模式

2023-12-13

我在 jQuery 中使用 SimpleModal,并且有一个确认对话框。如果结果是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。我该怎么做?


我不确定确认功能最适合您的需求,但这样的功能应该可以工作:

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()
                });
            });
        }
    });
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

jQuery 中的简单模式 的相关文章

随机推荐