-
-
Save moodpo/94c947c972465945016f to your computer and use it in GitHub Desktop.
使用H5特性上传图片
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 lang="zh-cn"> | |
<head> | |
<meta charset="utf-8" /> | |
<meta name="author" content="EdieLei" /> | |
<title>HTML5 图片上传预览</title> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> | |
<script type="text/javascript"> | |
$(function(){ | |
$('#img').change(function(){ | |
var file = this.files[0]; //选择上传的文件 | |
var r = new FileReader(); | |
r.readAsDataURL(file); //Base64 | |
$(r).load(function(){ | |
$('div').html('<img src="'+ this.result +'" alt="" />'); | |
}); | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<h3>HTML5 图片上传预览</h3> | |
<input id="img" type="file" accept="image/*" /><br /> | |
<div></div> | |
<hr> | |
<input type="text" mode=""> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment