我有这个代码,它在日历中的事件发生前30分钟显示警报,但我想在用户访问页面时显示一次(在30分钟内).现在它显示在每个页面刷新和日历刷新(在30分钟内),因为它被设置为在一段时间后刷新事件.如何只显示一次此警报?
var mili = event.start.getTime() - now.getTime();
if(mili < 1800000 && mili > 0){
$('.alert').dialog({
buttons: [{
text: "OK",
click: function() {
$( this ).dialog( "close" );
}
}]
});
}
Run Code Online (Sandbox Code Playgroud)
Fil*_*ilo 14
您可以使用localStorage(与旧版浏览器不兼容):
<script type="text/javascript">
var alerted = localStorage.getItem('alerted') || '';
if (alerted != 'yes') {
alert("My alert.");
localStorage.setItem('alerted','yes');
}
</script>
Run Code Online (Sandbox Code Playgroud)
或者你可以使用cookies,看看这个答案的完整示例代码:https: //stackoverflow.com/a/21567127/3625883