使用Html5实现异步上传文件,支持跨域,带有上传进度条

2020-04-21 22:59:40易采站长站整理

            </div>  
            <div style="margin:30px;width:500px;height:15px;border:1px solid #aeaeae;">  
                <div id="progress" style="background:#4cff00;height:15px;width:0%;"></div>  
                <div id="percentNumber"></div>  
            </div>  
            <div style="margin:30px;">  
                <div id="msg"></div>  
            </div>  
        </div>  
    </div>  
    <script type="text/javascript">  
        function fileSelected() {   
            //重置状态显示   
            document.getElementById("msg").innerHTML = "";   
            document.getElementById(‘percentNumber’).innerHTML = ”;   
            document.getElementById("progress").style.width = "0%";   
            var file = document.getElementById(‘fileInput’).files[0];   
            if (file) {   
                var fileSize = 0;   
                if (file.size > 1024 * 1024)   
                    fileSize = (Math.round(file.size * 100 / (1024 * 1024)) / 100).toString() + ‘MB’;   
                else