JavaScript / jQuery仅在第一次访问时执行,cookie阻止它再次执行 [英] JavaScript/jQuery only gets executed on first visit, cookie prevents it from executing again

查看:80
本文介绍了JavaScript / jQuery仅在第一次访问时执行,cookie阻止它再次执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让JavaScript(或jQuery)代码仅在访问者首次访问时执行,并且在cookie过期或删除之前不会再次执行?

How can I make JavaScript (or jQuery) code only execute on the visitor's first visit and never again until a cookie expires or is removed?

例如: $('#example')。hide(); 如何为此访问者阻止此代码执行7天?

For example: $('#example').hide(); How can I prevent this code from executing for 7 days for this visitor?

推荐答案

尝试这一点: http:// www。 electrictoolbox.com/jquery-cookies/
在第一次访问时设置一个cookie,在随后的访问中读出它并执行以下操作:

try this tut: http://www.electrictoolbox.com/jquery-cookies/ set a cookie on first visit, read it out on any subsequent visit and do something like:

if($.cookie.isset() == true) {
    // do something
}

这篇关于JavaScript / jQuery仅在第一次访问时执行,cookie阻止它再次执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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