【发布时间】:2015-10-05 10:22:08
【问题描述】:
我尝试使用引导程序中的警报来获取 cookie 通知。 我使用了以下代码:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js" </script>
<script src="src/jquery.cookie.js"></script>
<script type="text/javascript">
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', { expire 7, path: '/' });
});
});
</script>
<!-- Body Markup -->
<div class="alert alert-info fade in">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong> ALERT BODY</strong>
</div>
小提琴链接是: http://jsfiddle.net/Nighteyes/fy0w1vLc/
现在我希望在按下关闭按钮后设置一个 cookie。 cookie 将在 7 天后过期。
谁能帮帮我?
夜视
【问题讨论】:
标签: jquery html css twitter-bootstrap cookies