2 回答

TA貢獻1835條經驗 獲得超7個贊
很好的問題!如果我是你,我會更多地研究 localStorage。您完全正確地將值存儲在 localStorage 中是最好的方法。如果我正確理解你想要做什么,你的代碼應該如下所示:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<!-- jQuery Modal -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.1/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.1/jquery.modal.min.css" />
<div id="countryModal" NAME="country" class="modal">
<a rel="modal:close" href="#" onclick="gotoInternational()">Stay at International</a>
</div>
<script>
//Get current localStorage value
const gotoInternationalValue = localStorage.getItem('gotoInternational');
//Check if it is not true (can be false or null)
if (gotoInternationalValue != 'true') {
setTimeout(function() {
jQuery('#countryModal').fadeIn('slow').modal('show');
}, 3000)
} else {
console.log("Stay at international was already selected");
}
function gotoInternational() {
//Save localStorage item as true
localStorage.setItem('gotoInternational', true);
}
</script>
如果這不是您所需要的,請在您的問題中添加更多信息以澄清它!

TA貢獻1811條經驗 獲得超4個贊
我找到了解決方案!
您的解決方案是正確的,只是您在這里錯過了一個引號:
if (gotoInternationalValue != 'true' )
無論如何,感謝您的投入!拯救了我的一天!
添加回答
舉報