最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jshtml5 Displaying local storage - Stack Overflow

programmeradmin0浏览0评论

Is there a simple way to display my local storage with document.write or document.innerHTML methods? It's being stored on 1 page, trying to display on separate. I'm new to js and just unsure how to build the syntax of those methods with how I'm storing it(if possible).

 $('form').submit(function() {
    var person = $("#FirstName").val() + "." + $('#LastName').val();
 $('input, select, textarea').each(function() {
    var value = $(this).val(),
       name = $(this).attr('name');
       localStorage[person + "." + name] = value;
       window.location.href = "Confirmation.html";
    console.log('stored key: '+name+' stored value: '+value);
});   
});

heres the whole if it helps: /

Is there a simple way to display my local storage with document.write or document.innerHTML methods? It's being stored on 1 page, trying to display on separate. I'm new to js and just unsure how to build the syntax of those methods with how I'm storing it(if possible).

 $('form').submit(function() {
    var person = $("#FirstName").val() + "." + $('#LastName').val();
 $('input, select, textarea').each(function() {
    var value = $(this).val(),
       name = $(this).attr('name');
       localStorage[person + "." + name] = value;
       window.location.href = "Confirmation.html";
    console.log('stored key: '+name+' stored value: '+value);
});   
});

heres the whole if it helps: http://jsfiddle.net/EUWFN/

Share Improve this question asked Oct 29, 2013 at 19:21 user1user1 3572 gold badges13 silver badges22 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 14

As local storage is Object, you can go trough all it keys and get in values in simple way

for (var key in localStorage) {
  console.log(key + ':' + localStorage[key]);
}

To print it to the screen you can use something like this:

var output = ''; 

for (var key in localStorage) {
  output = output+(key + ':' +localStorage[key])+'\n';
}

$('#DivToPrintOut').html(output);

If you're using Chrome, press F12 for the Developers Tools.

In the Console type localStorage and press enter.

Or in your js code put console.log(localStorage);.

In the console, click on the little triangle next to line that begins with Storage.

Or in Dev Tools:

  1. click on the Resources tab at the top
  2. click on the little triangle next to Local Storage in the frame on the left
发布评论

评论列表(0)

  1. 暂无评论