Image upload display replacement

<div class="upload_box">
<div id="preview">
<img id="imghead" src="0.jpg" width="190" height="130"/> <!--图片显示位置-->
</div>
<b>上传图片</b>
<input type="file" name="file" id="file" accept="image/*" onchange="imgChange(this);"/> <!--文件上传选择按钮-->
</div>


<script type="text/javascript">

// select image to display

function imgChange(obj) {

//Get the clicked text box

var file =document.getElementById("file");

var imgUrl =window.URL.createObjectURL(file.files[0]);

var img =document.getElementById('imghead');

img. setAttribute('src',imgUrl); // Modify the value of the src attribute of the img tag


};


</script>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325982497&siteId=291194637