我试图寻找线索,但画了一大笔空白。可能我正在寻找错误的东西!
我在页面上创建了一个基本信息块。
我想通过点击x来为用户提供隐藏或关闭该框的选项。
我假设我需要使用cookie - 但不知道从哪里开始!也许是jquery,因为我已经在其他元素的每个页面上加载了它?
一个重要因素是它应该在显示新信息时重新出现。
怎么做的?有人可以帮忙吗?
谢谢!
答案 0 :(得分:0)
一旦你阅读了初学者javascript指南Nicolas为你链接,也许是一个jQuery tut,你可能最终会写这样的东西。
的Javascript
jQuery('div.xbutton').click(function(){
jQuery('div.infoblock').hide();
});
HTML
<div class="infoblock">Information text <div class="xbutton">X</div></div>
但是这是将来的,所以从阅读指南开始。这将是非常有用的:)
答案 1 :(得分:0)
您可以使用以下内容:
<div id="content" style="display:none;">
<span class="close">×</span>
Some text
</div>
<script>
jQuery(document).ready(function(){
if (!readCookie('messageClosed')){
jQuery('#content').show();
}
jQuery('#content .close').click(function(){
jQuery('#content').slideUp();
createCookie('messageClosed', 1, 365);
return false;
});
});
</script>
对于函数readCookie和createCookie,请查看:https://stackoverflow.com/a/1460174/2828391