[英]How can I get the local Storage Value
var cookieValue = document.getElementById("demo");
var value = cookieValue .getAttribute('value');
if(typeof(Storage)!=="undefined")
{
alert(value);
localStorage.setItem = ("GetData" , value);
alert(localStorage.setItem);
}
function loading()
{
alert("coming");
var allcookies = localStorage.getItem('GetData');
alert(allcookies);
}
Above is the way I am setting localStorage.setItem
and I am getting LocalStorage. 以上是我设置localStorage.setItem
的方式,我得到了LocalStorage。 But Where I didn't get the output it is showing Null. 但是我没有得到输出它显示Null。 Please Suggest me any Solution. 请建议我任何解决方案。
Your code should be : 你的代码应该是:
var cookieValue = document.getElementById("demo");
var value = cookieValue .getAttribute('value');
if(typeof(Storage)!=="undefined")
{
alert(value);
localStorage.setItem("GetData" , value);
alert(localStorage.getItem("GetData"));
}
function loading()
{
alert("coming");
var allcookies = localStorage.getItem('GetData');
alert(allcookies);
}
OR 要么
var cookieValue = document.getElementById("demo");
var value = cookieValue .getAttribute('value');
if(typeof(Storage)!=="undefined")
{
alert(value);
localStorage["GetData"] = value;
alert(localStorage["GetData"]);
}
function loading()
{
alert("coming");
var allcookies = localStorage["GetData"];
alert(allcookies);
}
The correct syntax for setItem
is setItem
的正确语法是
localStorage.setItem("GetData", value) localStorage.setItem(“GetData”,value)
not 不
localStorage.setItem = ("GetData", value) localStorage.setItem =(“GetData”,value)
Try this 试试这个
if( window.localStorage ) {
alert(value);
localStorage.setItem("GetData" , value);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.