码迷,mamicode.com
首页 > Web开发 > 详细

6.上传前图片预览

时间:2017-07-14 16:21:51      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:img   src   image   att   Enctype   type   .class   val   targe   

1、html 代码:

<div class="file-box">
<form action="upload.class.php" id="form_id" method="post" enctype="multipart/form-data" >
<input type="file" name="imagename" id="imagename" onblur="getimage(this)" />
<input type="button" class="btn" value="上传" onclick="form_register();" />
</form>
<img id="img_id" />
</div>

 

2、js代码

function getimage(obj)
{ 
  var pic = obj.files[0];
  var freader = new FileReader();
  freader.readAsDataURL(pic);
  freader.onload = function(e) {
  document.getElementById(‘img_id‘).attr("src",e.target.result);
  }

}

 

6.上传前图片预览

标签:img   src   image   att   Enctype   type   .class   val   targe   

原文地址:http://www.cnblogs.com/52-hz/p/7170339.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!