<input type="file" name="files" id="file1" ><input type="file" name="files" id="file2" ><input type="file" name="files" id="file3" >var file1= $('#file1').val();var file2= $('#file2').val();var file3= $('#file3').val();var fileArray =[file1,file2,file3];var fileType =['pdf','png','jpeg','jpg','xls','xlsx','doc','docx']; var count =0;for(var i=0;i<fileArray.length;i++){ var file= fileArray[i]; var start =file.indexOf('.')+1; var end =file.length; var suffix =file.substring(start,end); for(var j=0;j<fileType.length;j++){ if(suffix == fileType[j]){ count ++; } }}if(count !=3){ alert('附件的文件格式需为:pdf、png、jpeg、jpg、excel和word'); return;}for(var i=1; i<3; i++){ var fileInput =$('#file'+i)[0]; var byteSize =fileInput.file[0].size; var kbSize = Math.ceil(byteSize /1024); if(kbSize > 30720){ //不能超过30M alert('单个附件大小,不能超过30M'); return; }}