Using the H5 technology
/resources/images/icon4.png" style= "cursor:pointer;" height= "90px;" width= "95%;" >
<input id= "Headurladd" type= "file" Name= "HeadUrl1" onchange= "ReadFile (This)" style= "Display:none;"/>
<input type= "hidden" name= "Headurl" id= "logo" value= ""/>
JS as follows:
$ ("#headimg"). Click (function () {
AddHead (' Headurladd ');
});
function AddHead (obj) {
$ ("#" +obj). Click ();
}
function ReadFile (obj) {
var file = Obj.files[0];
Judging type is not a picture
/* IF (!/image\/\w+/.test (File.type)) {
Alert ("Make sure the file is of image type");
return false;
} */
var reader = new FileReader ();
Reader.readasdataurl (file);
Reader.onload = function (e) {
var imgbase64data =encodeuricomponent (E.target.result);
$ ("#headimg") [0].src=this.result;
var res = (This.result);
var pos = imgbase64data.indexof ("4") +4;
Imgbase64data = imgbase64data.substring (POS);
$ (' #logo '). Val (Imgbase64data);
}
}
JS implementation of the upload image function