前端页面要上传的图像显示

html

<div>
	<div id="pic_container">
		<label for="device_pic" id="label_pic">
			
			<img src="myassets/img/add.svg">
		label>
	div>
	<input type="file" id="pic">
	<p class="help-block">上传图片p>
div>

#pic_container{
	width: 200px;
    height: 200px;
}

#label_pic{
    border: 1px solid gainsboro;
    width: inherit;
    height: inherit;
}

#label_pic img{
    width: inherit;
    height: inherit;
    object-fit: contain;
    object-position: center;
}

jquery

$("#pic").change(function () {
	let fileList = this.files
	for (i = 0; i < fileList.length; i++) {
		$("#label_pic img").attr("src", URL.createObjectURL($(this)[0].files[i]))
	}
}

效果图:
前端页面要上传的图像显示_第1张图片
前端页面要上传的图像显示_第2张图片

你可能感兴趣的:(上传图片显示,笔记)