gpt4 book ai didi

javascript - 以编程方式打开 Bootstrap Alert

转载 作者:行者123 更新时间:2023-11-28 03:28:14 24 4
gpt4 key购买 nike

我正在尝试动态显示引导警报 https://getbootstrap.com/docs/4.3/components/alerts/显示一条消息以接受使用 cookie,一旦用户单击“确定”按钮,警报消息就会消失,并且在该 session 期间不会再次向该用户显示。

不幸的是,我在引导站点上找不到允许以编程方式打开引导警报的文档。因此,每次刷新网站时,都会再次弹出警报。

 <div class="alert fade show cookie-alert" role="alert" data-dismiss="alert">
<div class="container">
This website stores cookies. These cookies are used to collect information about how you interact with our website, we use this information to improve and customize your browsing experience. Read our <a target="_blank" href="http://assets.investnow.ng/InvestNow_TC.pdf" style="color:gray;font-weight:bold">terms and conditions</a> to learn more.
<button type="button" class="btn btn-danger btn-sm pull-right cookie-btn okbtn" data-dismiss="alert" aria-label="Close">OK</button>
</div>
</div>

最佳答案

请找到下面的代码

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

</head>
<body>
<div class="alert alert-dismissible">
<div class="container">
This website stores cookies. These cookies are used to collect information about how you interact with our website, we use this information to improve and customize your browsing experience. Read our <a target="_blank" href="http://assets.investnow.ng/InvestNow_TC.pdf" style="color:gray;font-weight:bold">terms and conditions</a> to learn more.
<button type="button" id="alertClose" class="btn btn-danger btn-sm pull-right cookie-btn okbtn" data-dismiss="alert" aria-label="Close">OK</button>
</div>


<script>
$(document).ready(function(){
localStorage.setItem("acceptCookies", true);
$(".alert").hide();
if (typeof(Storage) !== "undefined") {
if (localStorage.getItem("acceptCookies")) {
$(".alert").show();
$("#alertClose").click(function(){
localStorage.setItem("acceptCookies", "accepted");
$(".alert").alert("close");
});
}
}
});
</script>

</body>
</html>

关于javascript - 以编程方式打开 Bootstrap Alert,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58436537/

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