Skip to content

Instantly share code, notes, and snippets.

@zhoufenfens
Created August 13, 2013 07:43
Show Gist options
  • Save zhoufenfens/6218757 to your computer and use it in GitHub Desktop.
Save zhoufenfens/6218757 to your computer and use it in GitHub Desktop.
file uploader
function changehandler(){
console.log("change");
var file = document.getElementById('fileupload').files[0];
var reader=new FileReader();
reader.onload = (function(theFile) {
return function(e) {
console.log(e.target.result);
// img 元素
document.getElementById("img").src = e.target.result;
};
})(file);
reader.readAsDataURL(file);
}
document.getElementById("fileupload").addEventListener("change",changehandler,false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment