gpt4 book ai didi

jquery - SimpleModal 确认覆盖 : Would like callback to return true or false instead of URL redirect

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

嗨,我是一名 jquery 新手,正在尝试使用 simplemodal 插件。在此尝试之前,我的代码是

isYes = confirm("Are you sure . . . "?); 
return isYes;

simplemodal 演示执行 URL 重定向。我想像默认确认按钮那样返回 true 或 false。

这可能吗?

当我尝试此操作时(请参阅下面的代码),会弹出模式对话框,但它不会等待,而是在我可以单击任何内容之前继续执行底层按钮操作!

这就是我调用确认的方式:

confirm(confirm_message, function(isYes) { return isYes; });




function confirm(message, callback) {
var isYes = false;
$('#confirm').modal({
closeHTML: "<a href='#' title='Close' class='modal-close'>x</a>",
position: ["20%", ],
overlayId: 'confirm-overlay',
containerId: 'confirm-container',
onShow: function(dialog) {
var modal = this;

$('.message', dialog.data[0]).append(message);

// if the user clicks "yes"
$('.yes', dialog.data[0]).click(function() {
isYes = true;
// call the callback
if ($.isFunction(callback)) {
callback.apply(this, jQuery.makeArray(isYes));
}
// close the dialog
modal.close(); // or $.modal.close();

});


}
});
return isYes;
}

最佳答案

实现此功能的步骤:

1) 从“否”按钮中删除 simplemodal-close

2)在confirm.js中,更改:

// if the user clicks "yes"
$('.yes', dialog.data[0]).click(function () {
// call the callback
if ($.isFunction(callback)) {
callback.apply();
}
// close the dialog
modal.close(); // or $.modal.close();
});

致:

// if the user clicks "yes"
$('.buttons div', dialog.data[0]).click(function () {
var link = $(this);
// call the callback
if ($.isFunction(callback)) {
callback.apply(this, [link.hasClass('yes') ? true : false]);
}
// close the dialog
modal.close(); // or $.modal.close();
});

3)同样在confirm.js中,更改:

confirm("Continue to the SimpleModal Project page?", function () {
window.location.href = 'http://www.ericmmartin.com/projects/simplemodal/';
});

致:

confirm("Continue to the SimpleModal Project page?", function (response) {
// do whatever you need to do with response
});

希望有帮助。

-埃里克

关于jquery - SimpleModal 确认覆盖 : Would like callback to return true or false instead of URL redirect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4765169/

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