equ*_*sde 6 cookies jquery alert twitter-bootstrap
我试图记住这篇文章之后Twitter的Bootstrap警报中的关闭动作(使用Bootstrap,让警报框记住关闭动作)
我希望用户在关闭它并再次重新加载页面后无法看到警报.
我知道我必须将状态存储到cookie中,所以我使用了上面示例中建议的JQuery函数,但是不起作用.我究竟做错了什么?
小提琴 - > http://jsfiddle.net/kFy5y/
提前致谢!!
jQuery(function( $ ){
// Check if alert has been closed
if( $.cookie('alert-box') === 'closed' ){
$('.alert').hide();
}
// Grab your button (based on your posted html)
$('.close').click(function( e ){
// Do not perform default action when button is clicked
e.preventDefault();
/* If you just want the cookie for a session don't provide an expires
Set the path as root, so the cookie will be valid across the whole site */
$.cookie('alert-box', 'closed', { path: '/' });
});
});
Run Code Online (Sandbox Code Playgroud)
警报
<div class="alert alert-info fade in">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong> ALERT BODY</strong>
</div>
Run Code Online (Sandbox Code Playgroud)
您使用的$.cookie('alert-box')
不是标准 jQuery 函数,而是在jquery-cookie等库中实现的方法。
因此,您需要添加此库或类似的库才能使用 jQuery 保存 cookie。