// 验证附件格式和大小 function confirmData() { var flag = true; var message = ""; var errorSize = ""; var fileSuffix = $("#fileSuffix").val();//允许上传的附件格式 var maxSizeB = $("#maxSizeB").val();//允许最大上传单个附件大小 var i = 1; $("input[name='image']").each( function(){ var imageVal = $(this).val(); if(imageVal != "") { var suffix = imageVal.substring(imageVal.lastIndexOf('.')+1).toUpperCase(); if(fileSuffix.indexOf(suffix) == -1) { message += "【第"+i+"个】"; } var fileSize = $(this)[0].files[0].size; if(fileSize > maxSizeB) { errorSize += "【第"+i+"个】"; } }
i++; } ); if(message != "") { message += "不在允许上传附件的范围之类,请修正!<br/>" flag = false; } if(errorSize != "") { errorSize += "附件超过单个附件上传最大允许值,请修正!" message += errorSize; flag = false; } if(flag) { var form = document.getElementById('formId'); form.submit(); } else { layer.msg(message, { time: 5000, }); } }