如何限制用户一次最多上传10个文件? [英] How can restrict user to upload max 10 files at once?
本文介绍了如何限制用户一次最多上传10个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在网页中使用<input type="file" multiple="multiple">
上传文件(使用ajaxupload
).它将允许用户一次上传多个文件.但是我想限制用户一次只能选择10个文件.
I am using <input type="file" multiple="multiple">
in my web page to upload files (using ajaxupload
). It will allow user to upload multiple files at once. But I want to restrict user to select only 10 files at a time not more than that.
我该如何实现?
推荐答案
<input id="files" type="file" name="files[]" multiple="multiple" onchange="checkFiles(this.files)">
function checkFiles(files) {
if(files.length>10) {
alert("length exceeded; files have been truncated");
let list = new DataTransfer;
for(let i=0; i<10; i++)
list.items.add(files[i])
document.getElementById('files').files = list.files
}
}
此功能不允许选择10个以上的文件.
This function will not allow to select files more than 10.
这篇关于如何限制用户一次最多上传10个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文