This article is saved as an. html file opened in a browser to test functionality
<form id= "Form1" Name= "Form1" method= "Post" action= "" enctype= "Multipart/form-data";
<p> <input type= "hidden" name= "max_file_size" value= "100000"/></P>
<p><input name= " UserFile "id=" UserFile "type=" file "onchange=" Check () "/></P>
</form>
< Script language= "javascript" type= "Text/javascript",
function check ()
{
var aa= document.getElementById ("UserFile"). Value.tolowercase (). Split ('. '); /with "." Separate the upload file string
//var aa=document.form1.userfile.value.tolowercase (). Split ('. '); /with "." Separate upload file string
if (document.form1.userfile.value== "")
{
alert (' Picture cannot be empty! ‘);
return false;
}
Else
{
if (aa[aa.length-1]== ' gif ' | | aa[aa.length-1]== ' jpg ' | | aa[aa.length-1]== ' BMP '
|| aa[aa.length-1]== ' png ' | | aa[aa.length-1]== ' JPEG ')//Judging picture format
{
var imagsize = document.getElementById ("UserFile"). Files[0].size;
Alert ("Picture size:" +imagsize+ "B")
if (imagsize<1024*1024*3)
Alert ("The image size is within 3M, for:" +imagsize/(1024*1024) + "M");
return true;
}
Else
{
Alert (' Please select images formatted as *.jpg, *.gif, *.bmp, *.png, *.jpeg ');//jpg and JPEG format are just the same as the system Windows Jpg,mac OS recognition jpeg,
The difference between their own Baidu
return false;
}
}
}
</script>
JS upload file (image) Limited format and size of 3M