尝试使用 jQuery cookie 隐藏/显示框JS 饼干 https://github.com/carhartl/jquery-cookie,但我不知何故无法让它发挥作用。该框根本不会显示。我正在使用 Shopify。
#pop-up {
display: none;
}
Jquery:
<script type='text/javascript'>//<![CDATA[
$(window).load(function(){
// if no cookie
if (!$.cookie('alert')) {
$( "#pop-up" ).show();
$("#hide").click(function() {
$( "#pop-up" ).slideUp( "slow" );
// set the cookie for 24 hours
var date = new Date();
date.setTime(date.getTime() + 24 * 60 * 60 * 1000);
$.cookie('alert', true, { expires: date });
});
}
});//]]>
</script>
其余的部分:
<div id="pop-up">
<div id="center" class="box">
40% off today only<br>
<a id="hide" href="#">OK, thanks!</a>
</div>
</div>
它不起作用,因为你只能存储strings在饼干中。您存储字符串"true"
而不是布尔值true
.
尝试以下代码,我将支票替换为!= "true"
.
<script type='text/javascript'>//<![CDATA[
$(window).load(function(){
// if no cookie
if ($.cookie('alert')!="true") {
$( "#pop-up" ).show();
$("#hide").click(function() {
$( "#pop-up" ).slideUp( "slow" );
// set the cookie for 24 hours
var date = new Date();
date.setTime(date.getTime() + 24 * 60 * 60 * 1000);
$.cookie('alert', "true", { expires: date });
});
}
});//]]>
</script>
一个工作中的jsfiddle:http://jsfiddle.net/bqam0qb4/1/ http://jsfiddle.net/bqam0qb4/1/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)