zoukankan      html  css  js  c++  java
  • 如何通过js实现图片预览功能

    一、效果预览

    效果图:

    二、实现代码:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>js图片预览功能</title>
    <script language=javascript>
    function previewFile() {
      var preview = document.querySelector('img');
      var file    = document.querySelector('input[type=file]').files[0];
      var reader  = new FileReader();
      reader.onloadend = function () {
        preview.src = reader.result;
      }
      if (file) {
        reader.readAsDataURL(file);
      } else {
        preview.src = "";
      }
    }
    </script>
    </head>
    <body>
    <input type="file" onchange="previewFile()"><br>
    <img src="" height="200" width="300" alt="Image preview..."/>
    </body>
    </html>
  • 相关阅读:
    python 时间等待
    python threading多线程
    c 字符串的结束标志
    c 输出是自动显示输出类型
    c 的占位符
    c数据类型
    游戏引擎
    java 数据类型
    python 读写json数据
    python 多线程_thread
  • 原文地址:https://www.cnblogs.com/liuhongfeng/p/5019554.html
Copyright © 2011-2022 走看看