将布尔值存储在javascript的localStorage中? [英] Store booleans in javascript's localStorage?
问题描述
可能重复:
无法在LocalStorage中设置布尔值?
Possible Duplicate:
Cannot set boolean values in LocalStorage?
所以我一直在尝试使localStorage.test永久存储布尔值...
So i've been trying to get localStorage.test to store a boolean forever...
http://jsfiddle.net/abhi/aVmyt/
它总是以字符串形式存储.
And it always ends up storing as a string.
通过更改if语句中使用的条件来处理在提琴中创建的各种localStorage变量,并让我知道是否可以存储布尔值...
Play around with the various localStorage variables created in the fiddle by changing the condition used in the if statement, and do lemme know if you manage to store a boolean...
推荐答案
The W3C Storage interface specifies that values (and keys) are strings:
每个存储对象都提供对键/值对列表的访问, 有时称为项目.键是字符串.任何字符串 (包括空字符串)是有效键.值类似 字符串
Each Storage object provides access to a list of key/value pairs, which are sometimes called items. Keys are strings. Any string (including the empty string) is a valid key. Values are similarly strings
这篇关于将布尔值存储在javascript的localStorage中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!