Сообщение от Blondinka
|
результат будет null
|
а вы сделай не i а k++
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<p id="demo"></p>
<input type="text" name="name" />
<input type="text" name="email" />
<input type="text" name="telephone" />
<input type="submit" value="submit" />
<input type="submit" value="clear all" onclick="localStorage.clear();" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
var contacts = [],
k = 0;
$("input[type='submit']").click(function() {
var name = $('input[name="name"]').val(), //set user input to variables.
email = $('input[name="email"]').val(),
telephone = $('input[name="telephone"]').val();
contacts[k++] = [name, email, telephone];//Если эту строку заменить на contacts[i] = [name, email, telephone]; - результат будет null
//contacts[1] = ["Orlando", "orlando@jhk.com"];
localStorage["contacts"] = JSON.stringify(contacts);
alert(localStorage["contacts"]);
var contactList = JSON.parse(localStorage["contacts"]);
alert(contactList);
for(var i = 0; i < localStorage.length; i++){
$("body").append("<p>"+localStorage.key(i)+"="+localStorage.getItem(localStorage.key(i))+"</p>");
}
});
</script>
</body>
</html>