SoFunction
Updated on 2025-02-28

JavaScript implements preview before uploading pictures (TX's interview questions)

I didn’t know that the file control could also use onchange, which caused the interview to lose opportunities.

<script>
function yulan()
{
var fileext=document.(document.("."),document.)
        fileext=()

        if ((fileext!='.jpg')&&(fileext!='.gif')&&(fileext!='.jpeg')&&(fileext!='.png')&&(fileext!='.bmp'))
        {
alert("Sorry, the system only supports photos in standard formats. Please adjust the format and upload it again, thank you!");
             document.();
        }
        else
        {
//alert(''+document.)//Change this into a preview sentence
  ("preview").innerHTML="<img src='"+document.+"' width=120 style='border:6px double #ccc'>"
        }

}
</script>
<form name="form1" method="POST" enctype="multipart/form-data">
<input type="file" name="UpFile" size="46" onchange="yulan()">
<div ></div>
</form>