[英]Jquery Cookies expiration Time
I'm using this code to show two different DIV using jquery cookies. 我正在使用此代码使用jquery cookie显示两个不同的DIV。
<script type="text/javascript">
$(function showevent() {
$(window).load(function() {
if ($.cookie('MYCOOKIEVALUE') != '1'){
setTimeout(function(){
$('#event').fadeIn();
jQuery.cookie('MYCOOKIEVALUE', '1', { expires: 31});
}, 1000);}
if ($.cookie('MYCOOKIEVALUE') == '1'){
$('#event2').fadeIn();
}
});
});
</script>
I just need to modify the expiration time to 10 minutes using the exact code above. 我只需要使用上面的确切代码将到期时间修改为10分钟。 Still very new in javascript and jquery ;( Any help please
在javascript和jquery中还是非常新的;(请帮忙
To do such specific timing you will need to use Javascript's built in Date object, like so: 要做这样的特定时间,你需要使用Javascript的内置Date对象,如下所示:
var date = new Date();
date.setTime(date.getTime() + (10 * 60 * 1000));
This works in milliseconds, so 1000 seconds x 60 seconds per minute x 10 minutes total, then change the line in your script above to use the new expiration date: 这可以在几毫秒内完成,所以1000秒×60秒/分钟×10分钟,然后更改上面脚本中的行以使用新的到期日期:
jQuery.cookie('MYCOOKIEVALUE', '1', { expires: date});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.