html指定类型文件怎么上传,html – 如何在上传之前在多个输入类型文件中附加文件...

我有像你这样的问题

现在我找到了解决方案

var selDiv = "";

var storedFiles = []; //store the object of the all files

document.addEventListener("DOMContentLoaded", init, false);

function init() {

//To add the change listener on over file element

document.querySelector('#attachfile').addEventListener('change', handleFileSelect, false);

//allocate division where you want to print file name

selDiv = document.querySelector("#filelist");

}

//function to handle the file select listenere

function handleFileSelect(e) {

//to check that even single file is selected or not

if(!e.target.files) return;

//for clear the value of the selDiv

selDiv.innerHTML = "";

//get the array of file object in files variable

var files = e.target.files;

var filesArr = Array.prototype.slice.call(files);

//print if any file is selected previosly

for(var i=0;i

{

selDiv.innerHTML += "

" + storedFiles[i].name + "
";

}

filesArr.forEach(function(f) {

//add new selected files into the array list

storedFiles.push(f);

//print new selected files into the given division

selDiv.innerHTML += "

" + f.name + "
";

});

//store the array of file in our element this is send to other page by form submit

$("input[name=replyfiles]").val(storedFiles);

}

这正在我的页面正常工作,我希望这对你也有用

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值