Last active
August 29, 2015 14:19
-
-
Save weishai/05b99dff6f2d9840e821 to your computer and use it in GitHub Desktop.
Image convert to Base64
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> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> | |
<meta charset=utf-8 /> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<input type='file' id="asd" /> | |
<img id="img" src="" /> | |
<div id="base"></div> | |
</body> | |
</html> |
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
function readImage(input) { | |
if ( input.files && input.files[0] ) { | |
var FR= new FileReader(); | |
FR.onload = function(e) { | |
$('#img').attr( "src", e.target.result ); | |
$('#base').text( e.target.result ); | |
}; | |
FR.readAsDataURL( input.files[0] ); | |
} | |
} | |
$("#asd").change(function(){ | |
readImage( this ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment