我已使用下面的代码 - 来自https://www.w3schools.com/howto/howto_js_alert.asp - 创建一个警报框,当用户点击" x"盒子里面的按钮。但只要用户加载另一个页面,该框就会再次出现。
我希望用户只看一次此框;也就是说,点击它后它不再出现。
此网站和javascript的新功能 - 非常感谢有关应在下面的脚本中添加内容的建议,以便用户点击它后不会重新显示该框。
<div class="alert">
<span class="closebtn"onclick="this.parentElement.style.display='none';">×</span>
<a style="color:#fff" href="//www.google.com/">Click this link</a>
<script>
var acc = document.getElementsByClassName("closebtn");
var i;
for (i = 0; i < acc.length; i++) {
acc[i].onclick = function(){
var div = this.parentElement;
div.style.opacity = "0";
setTimeout(function(){ div.style.display = "none"; }, 600);
}
}
</script>
<style>
/* The alert message box */
.alert {
position: fixed; z-index:100; bottom: 0px; width:100%;
padding: 20px;
background-color: #f44336; /* Red */
color: white;
/* margin-bottom: 15px; */
}
/* The close button */
.closebtn {
margin-left: 15px;
color: white;
font-weight: bold;
float: right;
font-size: 22px;
line-height: 20px;
cursor: pointer;
transition: 0.3s;
}
/* When moving the mouse over the close button */
.closebtn:hover {
color: black;
}
</style>