0
我在使用bootstrap navbar-inverse的页面上有div。当页面加载时,用户将点击关闭按钮,然后设置一个cookie在2天内过期。所以下一次用户进入页面并且cookie过期时,div将被隐藏。否则显示div。感谢您的回应。将Cookie设置为在div上过期
//这里是div上的其他内容。
<div id="myFooter">
<div class="navbar-inverse1 navbar-fixed-bottom" role="navigation">
<div class="container">
<div class="navbar-text pull-right">
<button type="button" class="close" id="myButton" data-dismiss="navbar">×</button>
<h1 class="text-center">Do Something Here</h1>
<p>Lorem ipsum is a pseudo-Latin text used in web design, typography, layout, and printing in place of English to emphasise design elements over content. It's also called placeholder (or filler) text. It's a convenient tool for mock-ups. It helps to outline the visual elements of a document or presentation, so to deliberately render its content nonsensical; it's not genuine, correct, or comprehensible Latin anymore. While lorem ipsum's still resembles classical Latin</p>
</div>
</div>
</div>
</div>
//这里是脚本,但不能让它工作。
<script>
$(document).ready(function() {
// initially popup click to hide:
$('.close').click(function() {
$('#myFooter').hide();
});
// Check for the "whenToShowPopup" cookie, if not found then show the popup and save the cookie.
// The cookie will expire and every 2 days and the popup will show again.
limit = 5;
idleTime = 0;
if ($.cookie('whenToShowPopup') == null) {
function timerIncrement() {
idleTime = idleTime + 1;
if (idleTime > $limit && $.cookie('whenToShowPopup') != 'yes') {
$('#myFooter').show();
idleTime = 0;
console.log('whenToShowPopup', 'idleTime');
// Create expiring cookie, 2 days from now:
$.cookie('whenToShowPopup', 'yes', {
expires: 2,
path: '/'
});
// Show Popup
$('#myFooter').hide();
console.log('whenToShowPopup', 'cookie created');
};
});
});
</script>
感谢您的回复。 –
该代码运行时没有错误,但我不确定它是否正在创建cookie。它没有做任何console.log。 –
console.log的cookie,甚至更好。 (当你的应用程序打开时)按下chrome,按下'ctrl + shift + i'。转到应用程序选项卡并在存储选项卡下查看cookie,看看您的cookie是否在那里。 :) – matt