<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery上传图片之前可以预览效果</title>
<script src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
<style>
</style>
</head>
<body>
<input id="file" ;="" onchange="c()" type="file"><br>
<img src="" id="show" width="200"><script>
function c () {
var r= new FileReader();
f=document.getElementById('file').files[0];
r.readAsDataURL(f);
r.onload=function (e) {
document.getElementById('show').src=this.result;
};
}</script>
</body>
</html>
本文介绍了一种使用jQuery实现的图片上传预览功能,通过读取文件对象并将其转换为Data URL,实现在用户选择图片后立即在页面上预览所选图片的效果。
1732

被折叠的 条评论
为什么被折叠?



