As follows:
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("The uploaded attachment must be a photo.");
attachment.focus();
return false;
}
if (getFileSize(attachment) > 1024 * attachmentSizeArray[index].value){
alert("The uploaded attachment cannot be larger than " 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;
}
The first method is to get all the file controls of the page and the corresponding file size limit,
The key point is the second method, which is very cleverly solved with an image, (*^__^*) Hee hee...