对不起,如果我的问题重复,但我需要帮助 我试图将所选颜色保存到localstorage并在重新加载页面后保留最后选择的颜色。我的意思是在localstorage中获得最后保存的颜色 并在重新加载页面后用最后选择的颜色键入该框 任何想法?
const box = document.querySelector(".box");
const colorInput = document.querySelector("input");
const currentColorSpan = document.querySelector("#currentColorSpan");
colorInput.addEventListener("input", () => {
box.style.backgroundColor = colorInput.value;
currentColorSpan.textContent = colorInput.value;
});
.box {
width: 600px;
height: 360px;
border: solid 1px grey;
}
<div class="box">color slected not saved yet inside localstorag</div>
<label>click picker to choose color</label>
<input type="color" value="#ffffff"/>
<p>current color: <span id="currentColorSpan"></span></p>