vem*_*und 2 cookies jquery shopify
尝试使用JS Cookie制作 jQuery cookie 隐藏/显示框,但我不知何故无法使其工作。该框根本不会显示。我正在使用 Shopify。
#pop-up {
display: none;
}
Run Code Online (Sandbox Code Playgroud)
查询:
<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>
Run Code Online (Sandbox Code Playgroud)
其余的部分:
<div id="pop-up">
<div id="center" class="box">
40% off today only<br>
<a id="hide" href="#">OK, thanks!</a>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
它不起作用,因为您只能将字符串存储在 cookie 中。您存储字符串"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>
Run Code Online (Sandbox Code Playgroud)
一个有效的 jsfiddle:http : //jsfiddle.net/bqam0qb4/1/