2014-05-23 55 views
0
<script> 
$(document).ready(function(){ 
// Checks to see if div has been closed 
if(sessionStorage.getItem("hide") != true) { 
    $('#domainReco').show(); 
} else { 
    $('#domainReco').css("display", "none"); 
} 
$("#boxclose").click(function(){ 
    $("#domainReco").fadeOut(); 
    sessionStorage.setItem("hide", true); 
    return false; 
}); 
}); 
</script> 
echo '<div id="domainReco">'; 
    echo '<a class="boxclose" id="boxclose"></a>'; 
    echo '<h2>You are in the EU store</h2>'; 
    echo '<p>Want to visit the <a href="">US store</a> instead?<p>'; 
echo '</div>'; 

當點擊鏈接時,div會隱藏,但導航到另一頁後,div再次出現。我已經搜索,但似乎無法解決它。jQuery沒有保持div隱藏

在此先感謝

+1

jQuery是客戶端,所以當頁面重新加載其重置爲初始狀態 –

+0

您將需要使用Cookie使用jQuery用它發揮到淋漓盡致的時候 –

+1

,可以更換這個'$('#domainReco ').css(「display」,「none」);'用'$('#domainReco')。hide()' – dreamweiver

回答

3

您正在作出錯誤的比較。變量不保存爲bool,它們保存爲字符串。它應該是:

sessionStorage.getItem("hide") !="true"//not (sessionStorage.getItem("hide") !=true) 
+0

這是正確的,http://www.w3schools.com/html/html5_webstorage.asp顯示值存儲爲字符串 – RossBille

+0

@RossBille:謝謝你參考... –

+0

是的,這個固定它。謝謝! :) – DoYouEvenHTML