Home > Web Front-end > H5 Tutorial > HTML5 reads local file sample code_html5 tutorial skills

HTML5 reads local file sample code_html5 tutorial skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 15:47:59
Original
1729 people have browsed it

The html structure style is as follows:

Copy code
The code is as follows:









In terms of style, the input box of the input element should not be displayed. In this case, the input needs to be set to a transparent style, and then covered over the button element. Only then can the button be clicked to upload the image. . Set accepted to "image/*" to allow only image files to be uploaded.

Css style is as follows

Copy code
The code 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

Copy the code
The code is as follows:

function readFiles(evt){
var files=evt.target.files;
if(!files){
console.log("the file is invalid");
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);
}
}
}


Copy the code
The code is as follows:

$(document).ready(function(){
$("#logoimg").change(function(e ){
readFiles(e)
});
});
Related labels:
source:php.cn
Statement of this Website
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
Latest Issues
html5 validation for symfony 2.1
From 1970-01-01 08:00:00
0
0
0
The difference between HTML and HTML5
From 1970-01-01 08:00:00
0
0
0
html5 show hide
From 1970-01-01 08:00:00
0
0
0
Can PDF files run HTML5 and Javascript?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template