Skip to content

Instantly share code, notes, and snippets.

@ifukazoo
Last active August 29, 2015 14:00
Show Gist options
  • Save ifukazoo/11413430 to your computer and use it in GitHub Desktop.
Save ifukazoo/11413430 to your computer and use it in GitHub Desktop.
dot isntall HTML5 local storage の使い方
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<title>HTML5を使ったメモ帳</title>
</head>
<body>
<h1>メモ帳</h1>
<textarea id="memo" rows="10" cols="40"></textarea>
<p><input type="button" id="save" value="保存"> <input type="button" id="clear" value="消去"></p>
</body>
<script>
(function($) {
$(function() {
var memo = localStorage.getItem('memo');
if (memo) {
$('#memo').val(memo);
}
$('#save').click(function () {
localStorage.setItem('memo', $('#memo').val());
});
$('#clear').click(function () {
$('#memo').val('');
localStorage.removeItem('memo');
});
});
})(jQuery);
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment