Tip: You can modify some of the code before running
<!doctype HTML PUBLIC "-//w3c//dtd HTML 4.01//en" "HTTP://WWW.W3.ORG/TR/HTML4/STRICT.DTD" > <ptml xmlns= "http ://www.w3.org/1999/xhtml "> <pead> <meta http-equiv=" Content-type "content=" text/html; Charset=utf-8 "/> <title>javascript implementation picture preview function </title> </pead> <body> <input id=" myfile "t ype= "file"/> <br/> <div id= "info" ></div> <script type= "Text/javascript" > var dfile = do Cument.getelementbyid (' myfile '); var dimg = document.getelementsbytagname (' img ') [0]; var dinfo = document.getElementById (' info '); Dfile.onchange = function () {if (!dfile.value.match) (/.jpg|. Gif|. Png|. bmp/i)) {alert (' File type must be:. jpg,. gif,. bmp or. png! '); return;} if (dfile.files) {dimg.src = Dfile.files[0].getasdataurl (); }else if (dFile.value.indexOf (') >-1 | | | dFile.value.indexOf ('/') >-1) {dimg.src = Dfile.value; }} </script> </body> </ptml></td> </tr> </table>
Tip: You can modify some of the code before running