我正在創建一個記住您的名字的網站,並在您第二次重新加載頁面時歡迎您。我將數據存儲在localStorage中,因爲它比Cookie更好,並且永不過期,謝謝您的考慮!在localStorage中存儲提示響應並檢索
var person = prompt("please enter your name","you are...");
var person1 = +localStorage.getItem("person1");
if(person1 == null){
alert(person);
localStorage.setItem("person1");
}
if(person1 != null){
alert("welcome back " + person + "!");
}
爲什麼在localStorage之前有一個'+'?你在哪裏看到一個參數的setItem? [文檔顯示了兩個。](https://developer.mozilla.org/en-US/docs/Web/API/Storage/setItem) – epascarello