function hd() {
document.getElementById("Y").style.display = "none";
}
body {
display:grid;
place-content: center;
height:100vh;
overflow:hidden;
}
<div id="Y">i will be hidden</div>
<br>
<button onclick="hd();">click me</button>
重要的是存盤該函式,以便即使用戶重繪 我嘗試使用 cookie 的頁面也能正常作業,但僅通過呼叫該函式不起作用
uj5u.com熱心網友回復:
您可以設定一個標志,localStorage然后檢查是否已經設定了該標志并在啟動時再次呼叫該函式。
function hd () {
document.getElementById("Y").style.display = "none";
localStorage.setItem("hidden", "yes");
}
if (localStorage.getItem("hidden")) {
hd();
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/394859.html
標籤:javascript html
