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

js上传并且预览图片

时间:2017-05-03 14:32:50      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:back   set   his   end   asc   text   list   files   htm   

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script type="text/javascript" src = "jquery.js"></script>
</head>
<body>

<input id="upload" type="file" name="files" />

<div id = "box">
    
</div>
<script type="text/javascript">
var upload = document.getElementById(upload);
upload.addEventListener(change, function() {
      var file = upload.files[0];
      console.log(file.size);


      var reader = new FileReader();
    reader.readAsDataURL(file);
    reader.onload = function(e) {
      // var img = new Image();
      // img.src = this.result;
      // console.log(this.result);
      src = this.result;
      $(#box).append(
              "<img src ="+src+ ">"
          )

    };


}, false);

</script>

</body>
</html>

http://www.open-open.com/lib/view/open1456113131948.html

js上传并且预览图片

标签:back   set   his   end   asc   text   list   files   htm   

原文地址:http://www.cnblogs.com/wanghaonull/p/6801588.html

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