<body>
<div>
<input id="File1" type="file" />
<br />
<img src="" alt="" id="img1" style="width:300px; height:300px"/>
<br />
<span id="fn"></span>
<span id="fs"></span>
</div>
<script>
jQuery(function () {
$("#File1").on("change", function () {
var file = this.files[0];
if (this.files && file) {
var reader = new FileReader();
reader.onload = function (e) {
$("#img1").attr('src', e.target.result);
$("#fn").text(file.name);
$("#fs").text(file.size + "bytes");
}
reader.readAsDataURL(file);
}
});
})
</script>
</body>
上传图片的时候预览图片(单张)
最新推荐文章于 2021-07-05 15:00:39 发布