我浏览了论坛并阅读了许多与我的问题相关的帖子,但我无法真正找到我正在寻找的答案。
我想在页面加载时向用户显示带有 jquery 的消息,并允许他们通过单击关闭链接来关闭 div。一旦关闭,脚本应该记住不要在该 session 期间再次打开。我猜它会使用cookie。
这是 XHTML:
<div class="alertbox">
<span class="message">Please upgrade your browser</span>
<div class="bloc_navigateurs">
<a href="http://download.mozilla.org/?product=firefox-3.6.13&os=win&lang=fr" target="_blank"><img src="includes/themes/default/images/icons/misc/Firefox-16.gif" width="16" height="16" alt="Firefox" /></a>
<a href="http://www.google.com/chrome?hl=fr" target="_blank"><img src="includes/themes/default/images/icons/misc/Chrome-16.gif" width="16" height="16" alt="Chrome" /></a>
<a href="http://www.01net.com/telecharger/windows/Internet/navigateur/fiches/13759.html" target="_blank"><img src="includes/themes/default/images/icons/misc/IE-16.gif" width="16" height="16" alt="Internet Explorer " /></a>
</div>
<span class="close">close</span>
</div>
如您所见,这建议 IE6 用户升级他们的浏览器
最佳答案
我会使用 jQuery cookie plugin 。
为创建 cookie 的关闭链接的 onclick 事件绑定(bind)一个处理程序。在显示 div 之前,检查 cookie。
<script>
$(function() {
var $box = $(".alertbox"),
stateCookieName = 'alertbox_state',
alreadyClosed = $.cookie(stateCookieName);
// The box should already be hidden initially (using CSS preferrably).
// If not, uncomment the line below:
// $box.hide();
// Show the box if it hasn't already been closed.
if (alreadyClosed != 1) {
$box.show();
}
$box.find('.close').click(function() {
$box.hide();
$.cookie(stateCookieName, 1);
});
});
</script>
关于jquery - 在页面加载时显示启用 cookie 的 Jquery 通知消息,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4475400/