Paste the following content to notepad, change the suffix to html to run ################################## ############### <input name = "txtImg" type = "file" id = "txtImg"/> <input name =" btnUploadImg "type =" button "id =" btnUploadImg "value =" Upload "/> <span class =" redcolor "> (optimal image size: the width cannot exceed 600 pixels, and the height cannot exceed 600 pixels.) </span> <script language = "javascript"> var AllowImgFileSize = 512; // The size of the image file that can be uploaded 0 is unrestricted unit: KB var AllowImgWidth = 600; // The width of the image that can be uploaded 0 is unrestricted unit: px (pixel) var AllowImg Height = 600; // The Height of the image to be uploaded 0 is unrestricted unit: px (pixel) function checkImg () {var txtImg = document. getElementById ("txtImg"); if (txtImg. value = "") {alert ("click the Browse button to select the JPG or GIF file you want to upload! "); TxtImg. focus (); return false;} var txtImg_url = txtImg. value. toLowerCase (); var txtImg_ext = txtImg_url.substring (txtImg_url.length-3, txtImg_url.length! = "Jpg" & txtImg_ext! = "Gif") {alert ("select a JPG or GIF file! "); TxtImg. select () document.exe cCommand ("Delete"); txtImg. focus (); return false;} var ErrMsgErrMsg = ""; // error message var img = new Image (); img. src = \ '# \' "/> if (img. width> AllowImgWidth) {ErrMsgErrMsg = "\ n the image width exceeds the limit. upload a file whose width is smaller than" + AllowImgWidth + "px. The current image width is" + img. width + "px"; www.2cto.com alert (ErrMsgErrMsg); return false;} if (img. height> AllowImgWidth) {ErrMsgErrMsg = "\ n the image height exceeds the limit. please upload the image height less than" + AllowImgHeight + "px The current image height is "+ img. height + "px"; alert (ErrMsgErrMsg); return false;} var size = formatNum (img. fileSize/, 2); if (size> AllowImgFileSize) {ErrMsgErrMsg = "\ n the image file size exceeds the limit. upload a file smaller than" + AllowImgFileSize + "KB, the current file size is "+ size +" KB "; alert (ErrMsgErrMsg); return false;} alert ('OK! '); Return true ;} ############ auxiliary functions ############### function formatNum (amt, pre) {pre = pre> 0 & pre <= 20? Pre: 2; amt = parseFloat (amt + ""). replace (/[^ \ d \. -]/g ,"")). toFixed (pre) + ""; var left = amt. split (". ") [0]. split (""). reverse (); var right = amt. split (". ") [1]; var t =" "; for (I = 0; I <left. length; I ++) {t + = left [I] + (I + 1) % 3 = 0 & (I + 1 )! = Left. length? "": "") ;}Return t. split (""). reverse (). join ("") + "." + right ;}</script>