[英]How do I remove a file selection from file uploads when multiple files is selected with X button near the image preview with asp.net and jquery
I'm trying to create a site where I can have multiple file upload sections, where the user can upload multiple files.我正在尝试创建一个可以有多个文件上传部分的网站,用户可以在其中上传多个文件。 My problem comes from allowing the user to 'remove' a file from the upload list, before it's uploaded.
我的问题来自允许用户在上传之前从上传列表中“删除”文件。
.aspx .aspx
<label for="inputAddress">Select Media</label>
<div class="input-group mb-4">
<div class="custom-file">
<asp:FileUpload ID="ImageUploadsFP" runat="server" AllowMultiple="true" accept="image/*" onchange="ShowImagePreview(this);" class="multi" />
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" ValidationExpression="([a-zA-Z0-9\s_\\.\-:])+(.png|.PNG|.JPG|.jpg|.gif|.GIF|.mp4|.MP4|.MPV|.mpv|.mov|.MOV)$"
ControlToValidate="ImageUploadsFP" runat="server" ForeColor="Red" ErrorMessage="Please select a valid image file (.jpg / .png / .gif/ .mp4 / .mpv / .mov)"
Display="Dynamic" />
</div>
</div>
<div class="input-group mb-4">
<div id="previewImages">
<%--<asp:Image ID="ImgPrv" Height="150px" Width="240px" runat="server" />--%>
</div>
</div>
These are my jquery codes这些是我的 jquery 代码
<script language= "javascript" type = "text/javascript" >
$(function () {
$("[id*=ImageUploadsFP]").change(function () {
if (typeof (FileReader) != "undefined") {
var previewImages = $("#previewImages");
previewImages.html("");
var regex = /^([a-zA-Z0-9\s_\\.\-:])+(.jpg|.jpeg|.gif|.png)$/;
$($(this)[0].files).each(function () {
var file = $(this);
if (regex.test(file[0].name.toLowerCase())) {
var reader = new FileReader();
reader.onload = function (e) {
var img = $("<img />");
img.attr("style", "height:150px;width: 200px");
img.attr("src", e.target.result);
previewImages.append(img);
}
reader.readAsDataURL(file[0]);
} else {
alert(file[0].name + " is not a valid image file.");
previewImages.html("");
return false;
}
});
} else {
alert("This browser does not support HTML5 FileReader.");
}
});
});
</script>
How do i create a "X" button with the existing jquery script as I have tried multiple ways but it don't work.如何使用现有的 jquery 脚本创建“X”按钮,因为我尝试了多种方法,但它不起作用。
<img id="ImageFile" src=" " alt="Image" style="height:100px; border:1px solid black; border-radius:5px" />
<button type="button" class="btn btn-outline-hover-danger btn-sm" id="DeleteImage">
<i class="fa flaticon2-cross"></i>
</button>
<script>
$(document).ready(function(){
$("#DeleteImage").click(function(){
$("#ImageFile").hide();
$("#DeleteImage").hide();
});
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.