Last active
August 29, 2015 14:00
-
-
Save ifukazoo/11413430 to your computer and use it in GitHub Desktop.
dot isntall HTML5 local storage の使い方
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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