原生JS多文件上传
2021-02-04 23:16
标签:type aci order load result multiple tip var func 原生JS多文件上传 标签:type aci order load result multiple tip var func 原文地址:https://www.cnblogs.com/chensv/p/13132010.html 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);
});
}