Skip to content

Instantly share code, notes, and snippets.

@goshmx
Created October 13, 2015 20:19
Show Gist options
  • Save goshmx/d79cf3df9cb06804c606 to your computer and use it in GitHub Desktop.
Save goshmx/d79cf3df9cb06804c606 to your computer and use it in GitHub Desktop.
Preview de imagen al cargar un archivo
<form id="form1" runat="server">
<input type='file' id="imgInp" />
<img id="target" src="#" alt="your image" />
</form>
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#target').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#imgInp").change(function(){
readURL(this);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment