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

Use js to preview local images to be uploaded_javascript skills

WBOY
Release: 2016-05-16 19:16:30
Original
1004 people have browsed it




  <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>
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