我需要将其隐藏div
24 小时。put
它不工作。
我想要一个简单的 JavaScript 代码,它允许我div
在点击预定的时间量时隐藏某个元素。
为了提供更多信息,我在加载主页时会出现一个建议框。我想要的是当div
点击关闭按钮时,它会设置一个 cookie 来保持盒子div
关闭 24 小时(1 天)。
简单的说,当div
按下关闭按钮时,框 div 会隐藏 24 小时。
注意:我有一个 javascript 代码,允许关闭按钮关闭框,但每次刷新都会重新加载。
项目文件的链接 (编者注:从不受信任的网站下载文件不安全,最好等待作者用代码编辑问题。)
谢谢大家 正确的代码是
$(document).ready(function() {
// If the 'hide cookie is not set we show the message
if (!readCookie('hide')) {
$('#applink').show();
}else {
$('#applink').hide();
}
// Add the event that closes the popup and sets the cookie that tells us to
// not show it again until one day has passed.
$('#playstorclose').click(function() {
$('#applink').hide();
createCookie('hide', true, 1)
return false;
});
});
// ---
// And some generic cookie logic
// ---
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);
}
<div class="playstorapp" id="applink" style="text-align: center;margin: auto">
<a id="playstorclose" href="JavaScript:void(0)">X</a>
<a class="applink" href="https://play.google.com/store/apps/details?id=com.aradev.net&rdid=com.aradev.net" target="_blank">
Download
</a>
</div>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句