• 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>
      <title> new document </title>
      <meta charset="UTF-8">
      <meta name="generator" content="editplus" />
      <meta name="author" content="" />
      <meta name="keywords" content="" />
      <meta name="description" content="" />
      <script src="jquery.min.js"></script>
          <script>
    
            function check() {
                
                var objFile = document.getElementById("fileId");
                if(objFile.value == "") {
                    alert("不能空")
                }
            
                console.log(objFile.files[0].size); // 文件字节数
                
                var files = $('#fileId').prop('files');//获取到文件列表
                if(files.length == 0){
                    alert('请选择文件');
                }else{
                    var reader = new FileReader();//新建一个FileReader
                    reader.readAsText(files[0], "UTF-8");//读取文件 
                    reader.onload = function(evt){ //读取完文件之后会回来这里
                        var fileString = evt.target.result; // 读取文件内容
                        alert(fileString);
                }
            }
            
        }
        </script>
     </head>
    
     <body>
        <div>
            上传文件 : <input type="file" name = "file" id = "fileId" /> 
            
            <button  type = "submit" name = "btn" value = "提交" id = "btnId" onclick="check()" /> 提交
        </div>
     </body>
    </html>
  • 相关阅读:
    wait 和 notify 方法
    synchronized关键字
    多线程之thread、runnable的区别
    CodeForces 213 E
    hdu 3038 并查集
    zoj 3349 dp + 线段树优化
    hdu 4419 线段树 扫描线 离散化 矩形面积
    hdu 4262(线段树)
    hfut 1287
    hdu 4747 (线段树)
  • 原文地址:https://www.cnblogs.com/hnhycnlc888/p/10177499.html
Copyright © 2020-2023  润新知