2013-01-14 36 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