gpt4 book ai didi

javascript - 图片提交后如何取消预览?

转载 作者:行者123 更新时间:2023-12-02 23:27:29 25 4
gpt4 key购买 nike

在我预览图像并提交后,该图像仍然保留在那里,并添加了消息评论。我希望图像预览在提交后自动删除。

这是我的 html 代码:

 function showPreview(objFileInput) {
if (objFileInput.files && objFileInput.files[0]) {
var fileReader = new FileReader();
fileReader.onload = function (e) {
$("#targetLayer").html('<img src="'+e.target.result+'" width="200px" height="200px" class="upload-preview" />');
$("#targetLayer").css('opacity','0.7');
$(".icon-choose-image").css('opacity','0.5');
}
fileReader.readAsDataURL(objFileInput.files[0]);
}
}

$("#image_name").change(function(e) {
showPreview(this);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="form-group" id="targetOuter">
<div id="targetLayer"></div>
<img src="photo.png" class="icon-choose-image" />
<div class="icon-choose-image">
<input name="image_name" id="image_name" type="file" class="inputFile" />
</div>
</div>

最佳答案

//Target the image element and remove 
$(.icon-choose-image).remove();

关于javascript - 图片提交后如何取消预览?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56673429/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com