gpt4 book ai didi

jquery - 设置 jQuery cookie 仅显示一次弹出窗口

转载 作者:行者123 更新时间:2023-12-03 21:51:44 25 4
gpt4 key购买 nike

我是 jQuery 的绝对新手。我正在学习,但有一条圣诞节消息,我需要立即启动并运行。

我已将这些内容包含在页面标题中:

<script type="text/javascript" src="scripts/jquery-1.7.min.js"></script>
<script type="text/javascript" src="scripts/jquery.cookies.2.2.0.min.js"></script>`

然后使用 jQuery 弹出窗口跟随消息。这是:

<script type="text/javascript">
$(document).ready(function() {
var id = '#dialog';

//Get the screen height and width
var maskHeight = $(document).height();
var maskWidth = $(window).width();

//Set height and width to mask to fill up the whole screen
$('#mask').css({'width':maskWidth,'height':maskHeight});

//transition effect
$('#mask').fadeIn(1000);
$('#mask').fadeTo("slow",0.7);

//Get the window height and width
var winH = $(window).height();
var winW = $(window).width();

//Set the popup window to center
$(id).css('top', winH/2-$(id).height()/2);
$(id).css('left', winW/2-$(id).width()/2-220);

//transition effect
$(id).fadeIn(2000);

//if close button is clicked
$('.window .close').click(function (e) {
//Cancel the link behavior
e.preventDefault();

$('#mask').hide();
$('.window').hide();
});

//if mask is clicked
$('#mask').click(function () {
$(this).hide();
$('.window').hide();
});

});

</script>

正文中我放置了消息:

<div style="top: 199.5px; left: 200px; display: none;" id="dialog" class="window">  
XMAS MESSAGE
<a href="#" class="close">Shut this popup.</a>
</div>

到目前为止一切顺利。下一步是不要一遍又一遍地用同样的信息让我的回访者感到厌烦(推迟六十天就足够了)。

所以我想使用 jQuery cookie 插件设置 cookie:

function setCookie() {
$.cookie('test_status', '1', { path: '/', expires: 60 });
return false;
}

下次访问者点击同一页面时就会发现,并且在消息过期之前不会显示圣诞节消息。

现在 if-else 语句是我还不熟悉的高级 jQuery 类型。那么,谁能给我解释一下吗?

最佳答案

此类内容可能会有所帮助:

$(document).ready(function(){   if ($.cookie('test_status') != '1') {    //show popup here    $.cookie('test_status', '1', { expires: 60}); }   });

关于jquery - 设置 jQuery cookie 仅显示一次弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8405634/

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