我创建了一个简单的 div 元素,其中包含通知和用于切换元素的关闭按钮
jQuery('.float_close').click(function() {
jQuery('.float_notice').fadeToggle('slow');
通过使用 cookie 来保持其关闭有多困难?
最佳答案
没那么难,但我建议在 http://plugins.jquery.com/cookie/ 之上使用一个额外的 JavaScript 插件 ( jQuery ) .
if ($.cookie('noticeVisibility') !== undefined
&& $.cookie('noticeVisibility') === 'hidden') {
// If a cookie that stores the visibility
// of the notice was set and it says 'hidden', hide the notice
jQuery('.float_notice').hide();
}
jQuery('.float_close').click(function () {
jQuery('.float_notice').fadeToggle('slow');
// Saves a cookie for later
$.cookie('noticeVisibility', 'hidden');
});
关于javascript - jQuery 关闭 Div 窗口 + cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17983909/