2012-06-28 12 views
7
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); 
} 

ऊपर मैं जिस तरह से localStorage.setItem सेट कर रहा हूं और मुझे स्थानीय स्टोरेज मिल रहा है। लेकिन जहां मुझे आउटपुट नहीं मिला, यह शून्य दिखा रहा है। कृपया मुझे कोई समाधान सुझाव दें।स्थानीय संग्रहण मूल्य

उत्तर

10

आपका कोड होना चाहिए:

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); 

} 

या

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); 

} 
+0

धन्यवाद यह काम कर रहा है। – srinu

+0

आपका स्वागत है। कृपया उत्तर के बाईं ओर स्वीकृत उत्तर आइकन का चयन करें, जिसने भविष्य में उपयोगकर्ताओं को सभी उत्तरों को पढ़ने के बिना सीधे सही उपयोगकर्ता को खोजने में मदद करने के लिए सबसे अधिक मदद की है। –

+0

आपकी 'getitem (' और 'setitem (' getItem ''और' setItem (' – Relic

3

setItem के लिए सही वाक्यविन्यास localStorage.setItem("GetData", value)localStorage.setItem = ("GetData", value) नहीं है।

+0

अपने सुझाव के लिए धन्यवाद की कोशिश करो। – srinu

0

इस

if(window.localStorage) { 
    alert(value); 
    localStorage.setItem("GetData" , value); 
} 
+0

आपके सुझाव के लिए धन्यवाद 'होना चाहिए। – srinu

संबंधित मुद्दे