As follows:
Copy Code code 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 ("Upload attachment cannot be greater 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 on the page and the size of the corresponding file file.
The key is the second method, very clever with an image to solve, (*^__^*) Xi hee ...