function checkAttachment(){ alert("here"); var attachmentArray = document.getElementsByTagName("input"); var attachmentSizeArray = document.getElementsByName("fileMaxSize"); var index = 0; for (var i = 0; i < attachmentArray.length; i++){ var attachment = attachmentArray[i]; if (attachment.type=="file"){ if (!isPhoto(attachment.value)){ alert("上传的附件必须是相片."); attachment.focus(); return false; } if (getFileSize(attachment) > 1024 * attachmentSizeArray[index].value){ alert("上传的附件不能大于" + attachmentSizeArray[index].value + "k."); attachment.focus(); return false; } index++; } } return true; }
function getFileSize(fileObject){ var image=new Image(); image.dynsrc=fileObject.value; return image.fileSize; }