var fileLists = [] $('#label').click(function(){ // var inputBefore = document.getElementById('inputBefore'); var $input = $("#myFile"); console.log(111) $input.on('change',function(){ var files =this.files; //filelist files = Array.prototype.slice.call(files); //所有轉化爲數組 fileLists = fileLists.concat(files); //顯示文件名面板 console.log(11) if (files.length !== 0) { console.log(111) var html = ''; for (var i = 0; i < files.length; i++) { html += "<li><span>" + files[i].name + "</span>  <span>"+"刪除</span></li>"; } $('.upload_ul').append(html); } }) $input.removeAttr("id"); // // // 咱們作個標記,再class中再添加一個類名就叫uploadImg var newInput = '<input class="uploadImg" type="file" id="myFile">'; $(this).append($(newInput)); })
<div class="file_upload"> <label id="label"> <!-- 上傳文件 --> <input type="file" multiple id="myFile"> </label> <span class="no_file">未選擇文件</span> <ul class="upload_ul"> </ul> </div>
相似多張上傳圖片,能夠添加劇覆文件html