Home > Web Front-end > JS Tutorial > javascript实现上传图片前的预览(TX的面试题)_表单特效

javascript实现上传图片前的预览(TX的面试题)_表单特效

WBOY
Release: 2016-05-16 19:09:49
Original
1117 people have browsed it

以前不知道 file 控件也能使用 onchange,导致面试时失去良机。

<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="javascript实现上传图片前的预览(TX的面试题)_表单特效" >" <BR> } <br><br>} <BR></script>





source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template