Created
February 23, 2013 06:33
-
-
Save danimal141/5018720 to your computer and use it in GitHub Desktop.
use file API sample
This file contains 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> | |
<head> | |
<meta charset="utf-8"> | |
<title>ファイル読み込みサンプル</title> | |
</head> | |
<body> | |
<form> | |
<input id="upload" type="file"/> | |
</form> | |
<div id="img_area"> | |
<p>ここに画像表示しますよー</p> | |
</div> | |
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> | |
<script> | |
$("#upload").on("change", function(event){ | |
var file = event.target.files[0]; | |
var reader = new FileReader(); | |
reader.onload = function(e){ | |
$("#img_area").empty().append($("<img>").attr("src", e.target.result)); | |
}; | |
reader.readAsDataURL(file); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment