$(function(){ $("#image").change(function (){ var reader = new FileReader(); reader.readAsDataURL(this.files[0]); setTimeout(function() { //设置延时,否则取不到result值 $("#img").attr("src",reader.result); }, 100); }); });以上是js处理代码。
<img align="center" src="/image/yjz.png" height="240" alt="浏览器不支持" id="img"/>
<form action="" method="post" enctype="multipart/form-data">
<input id="image" type="file" accept="image/gif, image/jpeg, image/png" name="file" />
</form>
以上是html代码。