gpt4 book ai didi

javascript - 使用 "accept"和 "deny"创建确认框

转载 作者:行者123 更新时间:2023-11-28 01:41:54 25 4
gpt4 key购买 nike

当用户访问我的网站时,如何制作一个包含接受和拒绝两个选项的对话框?我需要接受按钮才能继续访问我的网站,需要拒绝按钮才能将访问者带到他们的最后一个网页。

到目前为止我已经:

var confirmation = confirm('Do you want to continue on this website?');
if (!confirmation){
// Redirect the user to his last webpage:
history.go(-1);
}

最佳答案

如果你想使用jquery,那么你可以在页面中包含Jquery并定义以下函数

function confirmation(question) {
var defer = $.Deferred();
$('<div></div>')
.html(question)
.dialog({
autoOpen: true,
modal: true,
title: 'Confirmation',
buttons: {
"Accept": function () {
defer.resolve("true");//this text 'true' can be anything. But for this usage, it should be true or false.
$(this).dialog("close");
},
"Deny": function () {
defer.resolve("false");//this text 'false' can be anything. But for this usage, it should be true or false.
$(this).dialog("close");
}
}
});
return defer.promise();
};

然后按以下方式使用

 confirmation('Do you want to continue on this website?').then(function (answer) {

if (answer == "false") {
// your logic

}
else if (answer == "true") {
// your logic
}
});

关于javascript - 使用 "accept"和 "deny"创建确认框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20829701/

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