localStorage
only supports strings.
(localStorage
仅支持字符串。)
Use JSON.stringify()
and JSON.parse()
.(使用JSON.stringify()
和JSON.parse()
。)
var names = [];
names[0] = prompt("New member name?");
localStorage.setItem("names", JSON.stringify(names));
//...
var storedNames = JSON.parse(localStorage.getItem("names"));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…