functionCheckimgtype (input) {varThis_ = Document.getelementsbyname (' imgfile ') [0]; varfilepath =This_.value; varExtstart = Filepath.lastindexof (".")); varext =filepath.substring (Extstart, Filepath.length). toUpperCase (); if(Ext! = ". PNG "&& ext! =". GIF "&& ext! =". JPG ") {alert ("Image is limited to png,gif,jpg format"); return false; } varFile_size = 0; if($.browser.msie) {varIMG =NewImage (); IMG.SRC=filepath; if(Img.filesize > 0) { if(Img.filesize > 2 * 1024*1024) {alert ("The picture is not less than 2MB. "); Document.execcommand ("Delete"); return false; } } } Else{file_size= This_.files[0].size; Console.log (File_size/1024/1024 + "MB"); varSize = file_size/1024/1024; //alert (size); if(Size > 2) {alert ("The uploaded file size cannot exceed 2m! "); return false; } } return true; }
[Code snippet]javascript check picture size and format