Comment: This article mainly introduces the specific implementation of html5 reading local files. The html structure style, Css style and js code are as follows. Friends who need it can take a look
The html structure style is as follows:<div>
<button>Add picture</button>
<form>
<input type="file" multiple accept="image/*">
</form>
</div>
<img src="" >
From the style point of view, the input box of the input element should not be displayed. At this time, the input needs to be set to a transparent style and then overwrite it above the button element. Only then can click on the button to upload the image. Set accepted to image/*, only image file uploads are allowed.
The Css style is as follows
.addpic{
position:relative;
margin-left:100px;
width:95px;
height:30px;
}
.addlogo {
background: none repeat scroll 0 0 rgba(0, 0, 0, 0);
cursor: pointer;
font-size: 30px;
opacity: 0;
position: absolute;
right: 0;
top: 0;
z-index: 10;
}
js code
function readFiles(evt){
var files=evt.target.files;
if(!files){
console.log("the file is invaild");
return;
}
for(var i=0, file; file=files[i]; i++){
var imgele=new Image();
var thesrc=window.URL.createObjectURL(file);
imgele.src=thesrc;
imgele.onload=function(){
$("#showlogo").attr("src", this.src);
}
}
}
$(document).ready(function(){
$("#logoimg").change(function(e){
readFiles(e)
});
});