开发者

Hiding Elements Permanently

I have two buttons, "Yes" and "No". If user clicks on "Yes", I want to display a message that needs to be permanent.

Eg - I click on yes,the message should stay even after page rel开发者_运维百科oad or the next time the user logs in. It shouldn't appear again. Maybe possible if i delete the file or something.

I am able to hide all elements using hide() and then display a msg, but onpage reload, they come back..

Can you guys help?

Thanks


This is possible using html5's localstorage (but I've no experience in using that), or using the jQuery cookie plugin.

$(document).ready(
  function(){
    var msg = $.cookie('yesMsg');
    $('#messages').text('yesMsg');

    $('#messageSelectionDiv').click(
      function(){
         $.cookie('yesMsg',$(this).text() {expires: 30});
    });
  });


If the browser you are targeting supports HTML5, You can use HTML5 localStorage, otherwise cookies, to store some permanent data for the user.

For example:

if (localStorage['show_something'])
  // Show it
else
  // Hide it

To store it initially, you just set it:

  localStorage['show_something'] = true;

For more info, refer to this awesome doc: http://www.html5rocks.com/tutorials/offline/storage/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜