<div class="codetitle"> <span><a style="CURSOR: pointer" data="14597" class="copybut" id="copybut14597" onclick="doCopy('code14597')"><u>复제대码</u></a></span> 代码如下:</div> <div class="codebody" id="code14597"> <br><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 과도기적//EN"> <br><html> <br><머리> <br><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <br><script type="text/javascript"> <br>/**<br>* 파일 도메인에서 로컬 이미지 URL 가져오기 <br>*/ <br>function getFileUrl(sourceId) { <br>var url; <br>if (navigator.userAgent.indexOf("MSIE")>=1) { // IE <br>url = document.getElementById(sourceId).value; <br>} else if(navigator.userAgent.indexOf("Firefox")>0) { // Firefox <br>url = window.URL.createObjectURL(document.getElementById(sourceId).files.item(0)) ; <br>} else if(navigator.userAgent.indexOf("Chrome")>0) { // Chrome <br>url = window.URL.createObjectURL(document.getElementById(sourceId).files.item(0)) ; <br>} <br>URL 반환; <br>} <br><br>/**<br>* 브라우저에 로컬 이미지 표시 <br>*/ <br>function preImg(sourceId, targetId) { <br>var url = getFileUrl(sourceId); <br>var imgPre = document.getElementById(targetId); <br>imgPre.src = URL; <br>} <br></script> <br></head> <br><본문> <br><form action=""> <br><input type="file" name="imgOne" id="imgOne" onchange="preImg(this.id,'imgPre');" /> <br><img id="imgPre" src="" width="300px" height="300px" style="display: block;" /> <br></form> <br></body> <br></html> <br> </div>