我有一个问题就是杀了我,我试图隐藏一个div 24小时(div跨越一个窗口)但是我做了一些错误而且它没有用。请有人查看我的测试链接http://testare.besaba.com,我使用下面的代码,错误可能在css http://testare.besaba.com/fx.base/site/css/commontest.css中我在文件末尾添加了这行#span {display:none;}。我看到这里的代码工作正常jsfiddle.net/Nd4xb/,只在我的网站上它不起作用。
谢谢
Html代码:
<div id="span" class="promo_header">
<a href="javascript:void(0)" class="close_promo_header" id="close" onclick="hidePromoPanel('/');"><font color="white">Close </font><span>X</span></a>
<button>Clear cookie</button></div>
JavaScript代码:
<script>
$(document).ready(function () {
if (!readCookie('hide')) {
$('#span').show();
}
/*else {
$('#span').hide();
}*/
$('#close').click(function () {
$('#span').slideUp("slow");
createCookie('hide', true, 1)
return false;
});
$('button').click(function() {
eraseCookie('hide');
})
});
function hidePromoPanel() {}
function createCookie(name, value, days) {
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
var expires = "; expires=" + date.toGMTString();
} else var expires = "";
document.cookie = name + "=" + value + expires + "; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
}
function eraseCookie(name) {
createCookie(name, "", -1);
} </script>
答案 0 :(得分:1)
尝试这样的事情。刚刚在jsFiddle中构建它但无法保存,因为它很有趣:(
<div id="promo" style="display:none">
Some message here
<button>Ok</button>
</div>
<script>
function setCookie(c_name, value, exdays) {
var exdate = new Date();
if (exdays) exdate.setDate(exdate.getDate() + exdays);
var c_value = escape(value) + ((exdays) ? '; expires=' + exdate.toUTCString() : '');
document.cookie = c_name + "=" + c_value;
}
function getCookie(name) {
var re = new RegExp(name + "=([^;,]+)");
var value = re.exec(document.cookie);
return (value !== null) ? unescape(value[1]) : null;
}
if (!getCookie('promo')) {
document.getElementById('promo').style.display = 'block';
}
document.getElementById('promo').getElementsByTagName('button')[0].onclick = function () {
document.getElementById('promo').style.display = 'none';
setCookie('promo', '1', 1);
};
</script>