本地存储列表键

时间:2015-02-10 22:27:33

标签: javascript jquery html storage local

我想知道如何为键做:1,2,3 ...... 现在,这是我的代码:

    <input type='text' id='provedor' />
<input type='text' id='login' />
<input type='text' id='senha' />
<input type='text' id='link' />
<input type='text' id='id' />
<button onclick="save()" type="button">Save</button>
<script>function save(){
var json = {};
    json.login = $('#login').val();
    json.senha = $('#senha').val();
    json.link = $('#link').val();
    json.id = $('#id').val();
    var provedor = document.getElementById('provedor').value;
    localStorage.setItem(provedor, JSON.stringify(json));}    

我需要这个来列出结果。请帮我。非常感谢!!

1 个答案:

答案 0 :(得分:0)

如果您想要localStorage的所有密钥和结果:

  localStorage.setItem("a", 1);
  localStorage.setItem("b", 1);
  localStorage.setItem("c", 1);
  localStorage.setItem("d", 1);

    var store = [];
    for (var i = 0; i < localStorage.length; i++)
    {         
        store.push([localStorage.key(i), localStorage.getItem(localStorage.key(i))]);
    }
    console.log(JSON.stringify(store));

http://jsfiddle.net/0ehukdcu/1/