html代码:
<input type="file" name="choose" id="choose" accept="image/*">
<label for="choose">
<img alt="正面" id="Img" src="../../images/camera.png">
</label>
<p>正面</p>
js代码
$('#choose').change(function(){
$('p').css('display','none');
var objUrl = getObjectURL(this.files[0]) ;
if (objUrl) {
$('#Img').attr("src", objUrl);
}
function getObjectURL(file) {
var url = null;
if (window.createObjectURL != undefined) { // basic
url = window.createObjectURL(file);
} else if (window.URL != undefined) { // mozilla(firefox)
url = window.URL.createObjectURL(file);
} else if (window.webkitURL != undefined) { // webkit or chrome
url = window.webkitURL.createObjectURL(file);
}
return url;
}
});