welcome

原生JS多文件上传

   <div style="height: 100px; width: 100px; border: 1px solid red; position: relative;">
        点击上传
        <input onchange="uploadFile()" id="upload" multiple="multiple" type="file" accept="image/*;capture=camera"
            style="height: 100px;width: 100px;opacity: 0;position: absolute;top: 0;left: 0;" />
    </div>

 

    function uploadFile() {
            var input = document.getElementById('upload');
            var files = Array.prototype.slice.call(input.files);
            files.forEach(function (file, i) {
                var reader = new FileReader();
                reader.onloadend = function (e) {
                    var baseFileStr = this.result.substring((13 + file.type.length), this.result.length);
                    console.info("输出文件数据");
                    console.info(baseFileStr);
                }
                reader.readAsDataURL(file);
            });
        }

 

posted @ 2020-06-15 17:06  一首弦曲献仙音  阅读(410)  评论(0编辑  收藏  举报
//博文图片放大缩小 //飘桃花效果