我想通过向以下code
警报为alert("You Have Reached The MAXIMUM Upload Limit");
因此,当我在指定的限制中一一添加时,会出现alert
<div class="files col-sm-4" id="files1">
<input type="file" name="files1" id="imagesix" multiple />
<br />Selected files:
<ol class="fileList"></ol>
</div>
脚本
$.fn.fileUploader = function (filesToUpload) {
this.closest(".files").change(function (evt) {
for (var i = 0; i < evt.target.files.length; i++) {
filesToUpload.push(evt.target.files[i]);
};
var output = [];
for (var i = 0, f; f = evt.target.files[i]; i++) {
var removeLink = "<i class=\"fa fa-times fa-close removeFile\" href=\"#\" data-fileid=\"" + i + "\"></i>";
output.push("<li><strong>", escape(f.name), "</strong> ", removeLink, " </li> ");
}
$(this).children(".fileList")
.append(output.join(""));
});
};
var filesToUpload = [];
$(document).on("click",".removeFile", function(e){
e.preventDefault();
var fileName = $(this).parent().children("strong").text();
for(i = 0; i < filesToUpload.length; ++ i){
if(filesToUpload[i].name == fileName){
filesToUpload.splice(i, 1);
}
}
$(this).parent().remove();
});
$("#files1").fileUploader(filesToUpload);
答案 0 :(得分:1)
我为我的项目实现了此代码,但根据您的要求,您可以更改它。
$(function(){
$("input[type='submit']").click(function(){
var $fileUpload = $("input[type='file']");
if (parseInt($fileUpload.get(0).files.length)>2){
alert("You can only upload a maximum of 2 files");
}
});
});
答案 1 :(得分:0)
您可以使用Dropzone.js插件。它允许您根据需要进行配置。