此代码在Chrome和Firefox中运行良好,但在Edge和IE中运行相同时失败。为什么呢?
if (typeof(Storage) !== "undefined") {
localStorage.setItem("lastname", "Smith");
document.getElementById("result").innerHTML = localStorage.getItem("lastname");
} else {
document.getElementById("result").innerHTML = "Sorry, your browser does not support Web Storage...";
}
<div id="result"></div>