Example analysis of js upload picture and preview function

  • 2020-06-01 08:12:25
  • OfStack

This article illustrates the upload image and preview function of js. Share with you for your reference. The specific analysis is as follows:

Reference online 1 some people wrote a code to upload a picture in time preview function

<img id="imgTag" style="height: 100px;" alt="" />
<input type="file" />

function DisplayImage(fileTag,imgTagId){
var allowExtention=".jpg.png.gif";
var extentionArr=fileTag.value.split('.');
var extention = extentionArr[extentionArr.length-1];
alert("Please upload image!");
//for adveced broswer(the newest ie,chrome,ff)
var reader = new FileReader();
reader.onload = function(e){
document.getElementById(imgTagId).setAttribute("src", e.target.result);

I hope this article has been helpful to your javascript programming.

Related articles: