我使用下面的代碼保存在webstorage對象幾個內容,但我得到這個錯誤:對象不支持屬性或方法「setItem」
Error:-- Object doesn't support property or method 'setItem'
什麼建議嗎?我在IE(11)和Chrome(版本34.0.1847.131米 - 最新版本)都試過,同樣的問題。
<!DOCTYPE html>
<html>
<body>
<div id="result">Test</div>
<script>
// Check browser support
alert(typeof(Storage))
if (typeof(Storage) != "undefined")
{
// Store
Storage.setItem("lastname", "Smith");
// Retrieve
document.getElementById("result").innerHTML=localStorage.getItem("lastname");
}
else
{
document.getElementById("result").innerHTML="Sorry, your browser does not support Web Storage...";
}
</script>
</body>
</html>
使用localStorage而不是Storage。 – Ibrahim