【发布时间】:2020-07-13 09:48:17
【问题描述】:
你好,我有这个伪代码:
if(cookie set){
$("#notification").hide();
}
else {
$("#notification").show();
}
我怎样才能集成 jQuery Cookie 插件,所以如果它找到一个 cookie 那么它不会显示#notification?
谢谢
【问题讨论】:
你好,我有这个伪代码:
if(cookie set){
$("#notification").hide();
}
else {
$("#notification").show();
}
我怎样才能集成 jQuery Cookie 插件,所以如果它找到一个 cookie 那么它不会显示#notification?
谢谢
【问题讨论】:
if ($.cookie('whatever')) {
//exists
} else {
//nuthin!
}
如果您使用的是:http://plugins.jquery.com/project/Cookie
[编辑]您还可以:
if ($.cookie('whatever') !== null) {
//exists
} else {
//still nuthin
}
【讨论】:
假设你使用this插件:
if ($.cookie('the_cookie') ) DO_YOUR_WORK;
【讨论】:
这段代码对我有用:
<script>
if ($.cookie('whatever')) {
alert('exists');
} else {
alert('not exists');
}
//$.cookie('whatever', 'asd'); writing cookie..
</script>
【讨论】: