Home  >  Article  >  Web Front-end  >  Use js to preview local images to be uploaded_javascript skills

Use js to preview local images to be uploaded_javascript skills

WBOY
WBOYOriginal
2016-05-16 19:16:30982browse




  <script> <BR>function preview5(){ <BR>var x = document.getElementById("file5"); <BR> if(!x || !x.value) return; <BR>var patn = /\.jpg$|\.jpeg$|\.gif$/i; <BR>if(patn.test(x.value)){ <BR>var y = document.getElementById("img5"); <BR>if(y){ <BR>y.src = "file://localhost/" + x.value; <BR>}else{ <BR>var img=document.createElement("img"); img.setAttribute("src","file://localhost/"+x.value); <BR>img.setAttribute("width","120"); <BR>img.setAttribute("height","90"); <BR>img.setAttribute("id","img5"); <BR>document.getElementById("form5").appendChild(img); <BR> } <BR>}else{ <BR>alert("您选择的似乎不是图像文件。"); <BR>}} <BR></script>
Statement:
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