I didn't know that the file control could also use onchange before, which resulted in a missed opportunity during the interview.
<script> <BR>function yulan() <BR>{ <BR>var fileext=document.form1.UpFile.value.substring(document.form1.UpFile.value.lastIndexOf("."),document.form1.UpFile.value.length) <BR> fileext=fileext.toLowerCase() <br><br> if ((fileext!='.jpg')&&(fileext!='.gif')&&(fileext!='.jpeg')&&(fileext!='.png')&&(fileext!='.bmp')) <BR> { <BR> alert("对不起,系统仅支持标准格式的照片,请您调整格式后重新上传,谢谢 !"); <BR> document.form1.UpFile.focus(); <BR> } <BR> else <BR> { <BR> //alert(''+document.form1.UpFile.value)//把这里改成预览图片的语句 <BR> document.getElementById("preview").innerHTML="<img src='"+document.form1.UpFile.value+"' style="max-width:90%"border:6px double #ccc' alt="Use js to preview pictures before uploading them (TX interview question)_Image special effects" >" <BR> } <br><br>} <BR></script>