如何写Jquery cookie [英] How to write Jquery cookie

查看:127
本文介绍了如何写Jquery cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计的网站拥有100%的宽度+高度div,其中包含覆盖首页的图形。我想在用户第一次访问网站时向用户显示一次,欢迎来到网站点击此处进入,然后再次向该用户显示。

I am designing a website that has 100% width + height div containing a graphic overlaying the home page. I want to show this once to the user when they first visit the site, a kind of welcome to the site click here to enter then this would never been shown to that user again.

如何使用Jquery编写Cookie?非常感谢。

How do I write a cookie with Jquery to do this? Many thanks.

推荐答案

您可以尝试使用 jQuery Cookie插件

Cookie是一种持久存储的形式。当用户加载网页时,您可以检查他是否有某个Cookie。如果他没有,你向他显示启动页面并设置cookie。如果他有cookie设置意味着他以前在这里,你不需要做任何事情。下面的代码可以是一个解决方案,但我是从我的头写,所以你可能需要修改一下。假设您使用的是上述插件。

The cookie is a form of persistent storage. When a user loads the page, you check if he has a certain cookie. If he doesn't, you show him the splash page and set the cookie. If he has the cookie set that means he's been here before and you don't need to do anything. The following code could be a solution, but I'm writing it out of my head so you'd probably have to modify it a bit. It assumes you're using the plugin above.

if (visits = $.cookie('noOfVisits')) {
    $.cookie('noOfVisits', visits++);
} else {
    $.cookie('noOfVisits', 1);
    $('#splash').show();
}

我认为这是很自我解释。注意,cookie过期,研究如何使它最后只要你想要的。

I think that it's pretty self explanatory. Note that the cookie expires, research how to make it last as long as you want.

希望这有助于:)。

这篇关于如何写Jquery cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆