效果图:
HTML代码:
<div style="width:160px;height:220px;">
<img src="pic1.jpg" style="width:160px;height:200px;" id='img1'/><br>
<input type="file" onchange="f2(this)"/>
</div>
JavaScript代码:
function f2(obj){
document.getElementById('img1').src=window.URL.createObjectURL(obj.files[0]);
}