jquery - 如何创建 jquery cookie?

标签 jquery ruby-on-rails ruby-on-rails-4 coffeescript guiders.js

所以,如果你去我的staging server您将看到我使用 this tool. 添加的迷你教程

但是,如果您单击注册或任何其他页面,教程将不断弹出。那么,如何创建一个 cookie,以便每个用户只显示一次?

我已经尝试过jquery cookie ,尽管如此,无法弄清楚如何让它工作。

这就是我所做的:

1. Copied jquery.cookie.js into assets/javascript/jquery.cookie.js
2. Created a new file called cookie.js
3. Added this arbitrary code: $.cookie(guider, true);

现在请记住,我实际上不知道必须在 cookie.js 中放入哪些代码才能使其为guiders.js 工具添加 cookie。因此,引导线只会显示一次。

我们如何让它正常工作?每个用户仅显示一次。

Guiders.js 代码:

guiders.createGuider({
  buttons: [{ name: 'Next' }]
, description: 'Follow this short 7 tip tutorial and learn how to get the most out of Leap. It will only take a few minutes :)'
, id: 'first'
, next: 'second'
, overlay: true
, title: 'Welcome to LeapFM! Mini Tutorial:'
}).show();

guiders.createGuider({
  attachTo: '.title'
, buttons: [{name: 'Close'}, {name: 'Next'}]
, description: 'The number of leaps a song gets determines how high it will rank on the charts. A song with more leaps will rank higher than a song with less leaps.'
, id: 'second'
, next: 'third'
, position: 7
, title: 'Tip 1. Ranking system:'
});

guiders.createGuider({
  attachTo: '.arrow'
, buttons: [{name: 'Close'}, {name: 'Next'}]
, description: 'To add a leap to a song simply hit the up arrow. You must be logged in to add 1 leap. Users can only add 1 leap per song.'
, id: 'third'
, next: 'fourth'
, position: 2
, title: 'Tip 2. Adding leaps:'
});

guiders.createGuider({
  attachTo: '.title'
, buttons: [{name: 'Close'}, {name: 'Next'}]
, description: 'You can view the songs genres within the parentheses'
, id: 'fourth'
, next: 'fifth'
, position: 6
, title: 'Tip 3. Genres:'
});


guiders.createGuider({
  attachTo: '.song'
, buttons: [{name: 'Close'}, {name: 'Next'}]
, description: "By clicking the song title you can listen to the song, comment on it and share it with the social media buttons. But dont't do it yet, lets finish the tutorial first!"
, id: 'fifth'
, next: 'sixth'
, position: 7
, title: 'Tip 4. Listening to songs:'
});

guiders.createGuider({
  attachTo: '#query'
, buttons: [{name: 'Close'}, {name: 'Next'}]
, description: 'You can search songs by genre, title or artist.'
, id: 'sixth'
, next: 'seventh'
, position: 5
, title: 'Tip 5. Search:'
});

guiders.createGuider({
  attachTo: '.left'
, buttons: [{name: 'Close'}, {name: 'Next'}]
, description: 'You must be logged in to submit a song. LeapFM only accepts YouTube urls so your song must first be on YouTube.'
, id: 'seventh'
, next: 'eigth'
, position: 7
, title: 'Tip 6. Submit a song:'
});

guiders.createGuider({
  attachTo: '.newsongs'
, buttons: [{name: 'Close'}, {name: 'Next'}]
, description: "By clicking 'New songs' you will be able to view the songs from upload date (newest to oldest). Where as the default page displays songs by leap/rank."
, id: 'eigth'
, next: 'ninth'
, position: 7
, title: 'Tip 7. Newest to oldest:'
});

guiders.createGuider({
  attachTo: '.signup'
, buttons: [{name: 'Close'}]
, description: 'Sign up and start participating :)'
, id: 'ninth'
, next: 'tenth'
, position: 5
, title: 'Call to action!'
});

最佳答案

使用 jquery 和 cookie 非常简单。尝试执行类似的操作:

// set cookie  
$.cookie('my_cookie_name', 'value inside of it');  

// get cookie  
alert($.cookie('my_cookie_name'));  

// delete cookie  
$.cookie('my_cookie_name', null);  

祝你好运。

关于jquery - 如何创建 jquery cookie?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18285469/

相关文章:

ruby-on-rails - Kaminari 导航菜单不显示

ruby-on-rails - 无法让 Ajax 处理关注/取消关注按钮 - 遵循 Railstutorial.org,第 11 课

ruby - ActionMailer 未实例化正确的邮件程序类

ruby-on-rails - rails 从 url 中删除 Controller 路径

javascript - 防止中键点击打开链接

c# - 加载图像显示 ASP.NET 中的所有服务器端请求以及客户端请求

javascript - 组合 Javascript 函数

ruby-on-rails - 错误 : parent directory is world writable but not sticky

ruby-on-rails - 在 Ruby on Rails 中分享

javascript - 如何衡量Jquery事件委托(delegate)带来的性能优势?