我想知道如何为键做: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));}
我需要这个来列出结果。请帮我。非常感谢!!
答案 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));