这是检查所选文件类型是否与 Jquery 中允许的文件类型匹配的正确方法吗?
var selectedFiles = $('#add_post_file');
var allowedFiles = ['image/jpg','image/gif','image/png'];
var goodFiles = 0;
var numFiles = $('#add_post_file').get(0).files.length;
for(var i = 0; i < numFiles; i++){
var file = $('#add_post_file').files[i];
if(jQuery.inArray(selectedFiles.get(0).files[i].type, allowedFiles) > -1){
goodFiles++;
};
i++;
};
if(goodFiles == numFiles){
alert('good');
// continue
}
else{
alert('one or more files were incorrect file types.');
};
谢谢