function submit() { console.log(imgList) var imgLists = [] var formData = new FormData(); for (var i = 0; i < imgList.length; i++) { imgLists.push(imgList[i]) formData.append('files', imgLists[i]) } console.log(imgLists) // return false $.ajax({ url: 'url地址', type: 'POST', data: formData, processData: false, contentType: false, async: false, success: function(data) { console.log(data); } }) }
每次选中图片后将文件file添加到数组中
unction imgremove() { var imglist = document.getelementsbyclassname("z_addimg"); var mask = document.getelementsbyclassname("z_mask")[0]; var cancel = document.getelementsbyclassname("z_cancel")[0]; var sure = document.getelementsbyclassname("z_sure")[0]; f(var j = 0; j < imglist.length; j++) { imglist[j].index = j; imglist[j].onclick = function() { var t = this; mask.style.display = "block"; cancel.onclick = function() { mask.style.display = "none"; }; sure.onclick = function() { mask.style.display = "none"; t.setattribute("id", "remove"); $("#remove").remove(); }; } }; };