嗨,我有这样的伪代码:整合jQuery的饼干
if(cookie set){
$("#notification").hide();
}
else {
$("#notification").show();
}
如何集成了jQuery插件的Cookie,因此如果它发现一个Cookie,则它不显示#notification?
感谢
嗨,我有这样的伪代码:整合jQuery的饼干
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>
Cookies是最重要的事情或技术存储在客户端环境数据。 jQuery Cookie是一个简单轻量的插件,用于从客户端写入,读取和删除cookie。
首先,您需要下载jquery.cookie插件,只需将其添加到您的页面即可。
<head>
<script src="js/jquery.js"></script>
<script src="js/jquery.cookie.js"></script>
</head>
设置cookie的:
$.cookie('cookie_name', 'cookie_value', { expires: 7 });
获取的Cookie:
$.cookie('cookie_name');
删除Cookie:
$.cookie('cookie_name', null, { path: '/' });