原生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); }); }