Home >Web Front-end >JS Tutorial >How to display the preview effect of uploaded images in js compatible Firefox_javascript skills

How to display the preview effect of uploaded images in js compatible Firefox_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:58:021115browse

The example in this article describes the method of js compatible Firefox to display the preview effect of uploaded images. Share it with everyone for your reference. The specific implementation method is as follows:

<!doctype html> 
<html> 
<head> 
<meta content="text/html; charset=GBK" http-equiv="Content-Type" /> 
<title>Image preview example</title>
<style type="text/css">
 div {width:100px;height:100px;border: 1px #A3BFE7 solid;}
 img {width:atuo;height:atuo;}
</style> 
<script type="text/javascript"> 
 function viewPic() { 
 var oFReader = new FileReader();
 oFReader.onload = function(e) {
 document.getElementById("uploadPreview").src = e.target.result;
 }
 if (document.getElementById("uploadImage").files.length === 0) { 
 return;
 } 
 var oFile = document.getElementById("uploadImage").files[0];
 oFReader.readAsDataURL(oFile);
} 
</script> 
</head> 
<body>
<input id="uploadImage" type="file" name="myPhoto" 
onchange='viewPic();'/><br>
<img id="uploadPreview" src=""/>
</body> 
</html>

The operation effect is as shown below:

I hope this article will be helpful to everyone’s JavaScript programming design.

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