"HTML5 로컬스토리지 딕셔너리 저장·인출"의 두 판 사이의 차이

3번째 줄: 3번째 줄:
==예시==
==예시==
*예제: http://jmnote.com/html5/localStorage_dictionary.php
*예제: http://jmnote.com/html5/localStorage_dictionary.php
;localStorage_dictionary.php
<source lang='html5'>
<source lang='html5'>
<script>
<script>
var my_dictionary = {'foo':'hello', 'bar':'world'};
var dict1 = {'foo':'hello', 'bar':'world'};
localStorage.my_dictionary = JSON.stringify(my_dictionary);
localStorage.my_dictionary = JSON.stringify(dict1);
</script>
 
<a href='localStorage_dictionary2.php'>페이지 이동</a>
var dict2 = JSON.parse(localStorage.my_dictionary);
</source>
console.log( dict2 );
;localStorage_dictionary2.php
// Object {foo: "hello", bar: "world"}
<source lang='html5'>
console.log( dict2['foo']);
<script>
// hello
var dictionary = localStorage.my_dictionary;
console.log(dictionary);
// {"foo":"hello","bar":"world"}
</script>
</script>
</source>
</source>

2015년 1월 15일 (목) 00:41 판

HTML5 로컬스토리지 딕셔너리 저장

1 예시

<script>
var dict1 = {'foo':'hello', 'bar':'world'};
localStorage.my_dictionary = JSON.stringify(dict1);

var dict2 = JSON.parse(localStorage.my_dictionary);
console.log( dict2 );
// Object {foo: "hello", bar: "world"}
console.log( dict2['foo']);
// hello
</script>

2 같이 보기

3 참고 자료

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}