📜  sessionStorage on DOMContentLoaded javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:12.048000             🧑  作者: Mango

代码示例1
nameInput.addEventListener("input", () => {
  sessionStorage.setItem("name", nameInput.value);
});

emailInput.addEventListener("input", () => {
  sessionStorage.setItem("email", emailInput.value);
});

msgInput.addEventListener("input", () => {
  sessionStorage.setItem("message", msgInput.value);
});

document.addEventListener("DOMContentLoaded", () => {
  nameInput.value = sessionStorage.getItem("name");
  emailInput.value = sessionStorage.getItem("email");
  msgInput.value = sessionStorage.getItem("message");
});