简介:
如何实现建议的上传图片预览<div class="col-sm-5">
<input type="file" name="goodsPicture" id="goodsPicture" accept="image/*" 
如何实现建议的上传图片预览
<div class="col-sm-5">
<input type="file" name="goodsPicture" id="goodsPicture" accept="image/*" onchange="imgChange(this);" /> <!--文件上传选择按钮-->
<div id="preview">
<img id="imghead" src="${goods.goodsPicture }" width="260" height="180"/> <!--图片显示位置-->
</div>
<script type="text/javascript">
// 选择图片显示
function imgChange(obj) {
//获取点击的文本框
var file = document.getElementById("goodsPicture");
var imgUrl = window.URL.createObjectURL(file.files[0]);
var img = document.getElementById('imghead');
img.setAttribute ('src', imgUrl); // 修改img标签src属性值
};
</script>
</div>效果:



