zoukankan      html  css  js  c++  java
  • JS代码之《在线预览图片与TXT文档》

    代码如下:

    <!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=utf-8" />
    <script type="text/javascript"  src="jquery-3.2.1.min.js"></script>
    <title>在线预览图片与TXT文档</title>
    </head>

    <body>


    jsReadFile:<input type="file" onchange="jsReadFiles(this.files)"/>

    <script>
       function jsReadFiles(files) {
              if (files.length) {
                  var file = files[0];
                  var reader = new FileReader();//new一个FileReader实例
                 if (/text+/.test(file.type)) {//判断文件类型,是不是text类型
                      reader.onload = function() {
                          $('body').append('<pre>' + this.result + '</pre>');
                      }
                     reader.readAsText(file);
                 } else if(/image+/.test(file.type)) {//判断文件是不是imgage类型
                     reader.onload = function() {
                         $('body').append('<img src="' + this.result + '"/>');
                     }
                     reader.readAsDataURL(file);
                 }
             }
         }
    </script>

    </body>
    </html>

     

    效果图如下:

  • 相关阅读:
    8.13实习报告
    8.10实习报告
    8.9实习报告
    8.8实习报告
    8.7实习报告
    关于线索二叉树建立和遍历
    main函数的位置可以任意
    返回指针值的函数和函数指针的区别
    runtime error: store to address 0x625000002048 with insufficient space for an object of type 'double' (solution.c) 0x625000002048: note: pointer points here
    m=-n++
  • 原文地址:https://www.cnblogs.com/lwh0206/p/7866432.html
Copyright © 2011-2022 走看看