gpt4 book ai didi

jquery - jQuery 中的简单模式

转载 作者:行者123 更新时间:2023-12-01 03:57:20 24 4
gpt4 key购买 nike

我在 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()
});
});
}
});
}

关于jquery - jQuery 中的简单模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/394942/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com