2013-01-14 38 views
0

与加载页面时Cookie一起设置的某个JS存在问题,此时应仅在单击关闭该框时进行设置。在加载页面时立即停止Cookie设置

任何帮助,将不胜感激。下面的代码:

<!doctype html> 
<html lang="en"> 
<head> 
    <title></title> 
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> 
    <script type="text/javascript" src="http://resources.site.co.nz/scripts/jquerycookie.js"></script> 
    <script type="text/javascript"> 
    $(function() { 
     $('a.close').click(function() { 
      $(this).parent().fadeOut(1500); 
      $.cookie('hidden', 'true', { expires: null}); 
      alert($.cookie('hidden')); 
      return false; 
     }); 
     if($.cookie('hidden','true')){ 
      $('#errororganinfoinchide-this').hide(); 
     } 
    }); 
    </script> 
</head> 
<body> 
    <div id='boxes'> 
     <aside class='warning' id='errororganinfoinchide-this'> 
      <a href='#errororganinfoinchide-this' class='close'><img src='http://resources.site.co.nz/backgrounds/close.png' /></a> 
      <img src='http://resources.site.co.nz/backgrounds/icon_warning.png' class='messageimg' /> 
      <h4>Warning - Organisation Info</h4> 
      <p>Sorry, there was an error opening the "Organisation Info" Box. Please try again later.</p> 
     </aside> 
    </div> 
</body> 

+1

你有再次测试前清除缓存和Cookie? –

回答

2

不符合 “if($.cookie('hidden','true')){” 设置cookie,而不是读它?

这也许应该是这样的,而不是...

if($.cookie('hidden') == 'true'){

+0

这将是正确的。对我来说太愚蠢了。谢谢! –

+0

不知道这是否应该列为另一个问题。但是有可能获得$(this).parent()。我的意思是我希望得到正在关闭的内容的ID,并将其作为Cookie的名称。所以它会是这样的: '$ .cookie('#errororganinfoinchide-this','true',{expires:null});' –

+0

是的,这应该有效。如果您遇到问题,请打开一个新问题... – David