我想創建一個Bootstrap警報框,記得用戶何時單擊關閉按鈕。我想我需要將這些信息存儲在cookie中。理想情況下,cookie只會持續當前會話,接下來他們將返回該框將再次出現。使用Bootstrap,有警示框記住關閉動作
我正在使用jQuery-Cookie插件。我把它上傳到/jquery-cookie-master
。插件可以是found here。
這是我到目前爲止通過以下代碼found here。
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="/jquery-cookie-master/jquery.cookie.js"></script>
<script>
function runOnLoad(){
if($.cookie('alert-box') == null) {
$.cookie('alert-box', 'open', { expires: 7 });
} else if($.cookie('alert-box') == 'close') {
$(".close").hide();
}
</script>
HTML:
<body onload="runOnLoad()">
<div class="alert alert-info">
<button type="button" class="close" data-dismiss="alert" href="hideMe.php" onclick="hideMe()">×</button>
<p>
<strong>FORUM UPGRADE:</strong> In light of our recent surge in popularity we upgraded our forum and unfortunately lost all the old threads in the process.
</p>
<p>
In an effort to kick-start the forum again we need your help. Sign up now and leave a post (it's free). Once we reach 100 threads every member will receive a special gift.
</p>
<p>
<a href="http://example.com/forum/#/entry/register">
<strong>Sign up to the forum now</strong>
</a>.
</p>
</div>
</body>
可惜這不是working.When我點擊關閉按鈕後不記得動作,如果我刷新頁面會再次出現警告框。
我做錯了什麼?
燦有人幫忙嗎? – bennygill