Comments: This article mainly introduces the implementation of html5 to read local files. The html structure style, Css style, and js Code are as follows. If you need them, you can see the following html structure style:
The Code is as follows:
<Div class = "addpic">
<Button> Add image </button>
<Form>
<Input id = "logoimg" class = "addlogo" type = "file" multiple accept = "image/*" name = "logo">
</Form>
</Div>
In terms of style, the input box of the input element should not be displayed. In this case, you need to set the input to a transparent style and overwrite it to the top of the button element before clicking the button to upload the image. If you set accepted to "image/*", only image files can be uploaded.
The Css style is as follows:
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
The Code is as follows:
Function readFiles (evt ){
Var files‑evt.tar get. 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 );
}
}
}
The Code is as follows:
$ (Document). ready (function (){
$ ("# Logoimg"). change (function (e ){
ReadFiles (e)
});
});