The idea of js to implement upload image preview function is to obtain the local path of upload image, and then load it into the page to achieve upload preview
HTML code
<div class="upload"> <input type="button" class="btn" onclick="()" value="Upload"> <input type="file" style="display: none;" class="test"> <div class="img_center"> <img src="" class="img1-img"> </div> </div>
JS code that implements functions
//The method of obtaining the image is compatible with multiple browsers and is implemented through createObjectURLfunction getObjectURL(file){ var url = null; if( != undefined){ url = (file);//basic }else if( != undefined){ url = (file); }else if( != undefined){ url = (file); } return url; } //Implement function code$(function(){ $("#browerfile").change(function(){ var path = ; var objUrl = getObjectURL([0]); if(objUrl){ $('.img1-img').attr("src",objUrl); } }) })
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.