이 기사에서는 JS의 이미지를 업로드하기 전에 이미지 미리보기 효과를 구현하는 방법에 대해 설명합니다. 참조를 위해 공유하십시오. 특정 구현 방법은 다음과 같습니다.
다음과 같이 코드를 복사하십시오.
<html xmlns = "http://www.w3.org/1999/xhtml">
<헤드>
<meta http-equiv = "content-type"content = "text /html; charset = utf-8" />
<title> js </title>에 의해 사진을 업로드하기 전에 사진 미리보기 효과
</head>
<body>
<input id = "myFile"type = "file" />
<br />
<img src = "/images/logo.gif"/>
<div id = "info"> </div>
<script type = "text/javaScript">
var dfile = document.getElementById ( 'myfile');
var dimg = document.getElementsByTagName ( 'IMG') [0];
var dinfo = document.getElementById ( 'info');
dfile.onchange = function () {
if (! dfile.value.match (/.
if (dfile.files) {
dimg.src = dfile.files [0] .getasdataurl ();
} else if (dfile.value.indexof ( '//')> -1 || dfile.value.indexof ( '//') {{
dimg.src = dfile.value;
}
}
</스크립트>
</body>
</html>
이 기사가 모든 사람의 JavaScript 프로그래밍에 도움이되기를 바랍니다.