调用基于 jQuery Cookie 的函数
我有点困惑,可能错过了眼前的一些东西。
我正在使用 jQuery cookie 在我的页面中创建 cookie。代码是:
var $j = jQuery.noConflict();
$j(document).ready(function(){
$j.cookie("homecookie", 1, {expires: 30, path: '/'});
});
我知道读取 cookie 会是 $j.cookie('homecookie');
但在那之后我就感到困惑了。我需要调用这个函数 $j.colorbox({ inline:true, href:"#gallery-nav-instruct"});
如何调用?
换句话说,如果该人没有访问过该页面,则调用 colorbox。如果用户访问过该页面,则不会调用该页面。有人可以帮我正确设置它,因为我无法得到它。请举一些例子,因为 javascript 不是我的菜。
I am a bit confused and might be missing something in front of my face.
I am using jQuery cookie to create a cookie in my page. The code is:
var $j = jQuery.noConflict();
$j(document).ready(function(){
$j.cookie("homecookie", 1, {expires: 30, path: '/'});
});
I know to read the cookie it would be $j.cookie('homecookie');
but after that is where I get confused. I need to call this function $j.colorbox({ inline:true, href:"#gallery-nav-instruct"});
How?
In other words if the person has not visited the page then colorbox is called. If the user has visited the page then it is not called. Can someone help me set this up properly as I cannot get it. Please give examples as javascript is not my cup of tea.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以简单地检查 cookie 是否存在,如果不存在,您可以调用函数并设置 cookie:
You can simply check for the presence of the cookie, if it is not present you can call function and set the cookie:
好吧,只需检查 cookie 值:
或者如果确切的 cookie 值很重要,请进行比较:
在这两个示例中,我假设您希望在 cookie 不符合其应有的情况时调用 colorbox 内容当某个用户从未访问过时。
Well just check the cookie value:
Or if the exact cookie value is important, compare:
In both those examples, I'm assuming that you want to call the colorbox thing when the cookie is not what it should be when some user has never visited.