zoukankan      html  css  js  c++  java
  • web fileReader API

    1. code

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>WEB FILEREADER API</title>
      <style type="text/css">
       
    
      </style>
    </head>
    <body onClick="showFileName()">
        <input name="t"type = file id = 'file'/>
        
        <input type = button onclick = 'readImg()' value = '读取图像'/> 
        <input type = button onclick = 'readFile()' value = '读取文件'/>
        <div id = 'result'></div>
        <script language = 'javascript'>
          function showFileName(){
            var files = document.getElementById('file').files;
            var file;
            console.log(files)
            //console.log(1)
            for(var i = 0, len = files.length; i < len; i++){
              file = files[i];
              console.log(1)
              console.log(file.name);
            }
          }
          showFileName()
    
          function readImg(){
            var file = document.getElementById('file').files[0];
            console.log(file)
            if(!/image/w+/.test(file.type)){
              alert("请确保文件为图像类型!");
              return false;
            }
            var reader = new FileReader();
            reader.readAsDataURL(file);
            reader.onload = function(e){
                console.log(this)
              var result = document.getElementById('result');
              result.innerHTML = "<img src = '"+this.result+"' alt = ''/>";
            };
          }
    
          function readFile(){
            var  file = document.getElementById('file').files[0];
            var reader = new FileReader();
            reader.readAsText(file);
            reader.onload = function(f){
              var result = document.getElementById('result');
              result.innerHTML = this.result;
            }
          }
    
        </script>
    </body>
    </html>

    2. pic

    3. end

  • 相关阅读:
    iOS 自带系统语音识别
    对iOS10新增Api的详细探究
    iOS 技术前瞻
    iOS 之 byte NSString NSData类型转换
    iOS 文本属性
    基本力
    xamarin mac 基础知识 之 界面
    xamarin mac 之 基础知识
    xamarin mac 之 资料
    I方法 thinkphp
  • 原文地址:https://www.cnblogs.com/vali/p/6699393.html
Copyright © 2011-2022 走看看