gpt4 book ai didi

javascript - 仅显示一次弹出消息

转载 作者:行者123 更新时间:2023-11-30 14:42:49 27 4
gpt4 key购买 nike

我有一条弹出消息,每次用户访问我的网页时都会显示该消息。这很烦人,我只想显示一次弹出消息。怎么做?

<script>
$(document).ready(function () {
$("#popup").hide().fadeIn(1000);
//close the POPUP if the button with id="close" is clicked
$("#close").on("click", function (e) {
e.preventDefault();
$("#popup").fadeOut(1000);
});
});
</script>
<!-- Pop up message -->
<link href="myhome/popup.css" rel="stylesheet" type="text/css"/>
<div class="body-popup" style="height: 100%; width: 100%; background-color: black">
<div id="popup">
<div id="close" class="alert alert-info alert-dismissable">
<button type="button" class="pull-right close" data-dismiss="alert" aria-hidden="true">&times;</button>
CLOSE
<img src="/myhome/assets/img/prom.jpg" alt="popup" class="image-pop"/>
</div>
</div>
</div>

最佳答案

一旦他们看到它,将其保存在 localStorage 中。

$(document).ready(function () {
const popup = $("#popup");
popup.hide()
if (localStorage.seenPopup) return;
popup.fadeIn(1000);
//close the POPUP if the button with id="close" is clicked
$("#close").on("click", function (e) {
e.preventDefault();
$("#popup").fadeOut(1000);
localStorage.seenPopup = 'true'; // value doesn't matter as long as it's not falsey
});
});

关于javascript - 仅显示一次弹出消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49402240/

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