【发布时间】:2017-06-24 00:31:44
【问题描述】:
【问题讨论】:
【问题讨论】:
我们可以通过简单的jquery点击功能轻松实现。
这是我们的文件上传html,所以我们可以写一个点击函数
<input type="file" name="file-711" size="40" class="wpcf7-form-control wpcf7-file" id="imgupload" accept=".png,.jpg,.jpeg,.pdf,.doc,.docx" aria-invalid="false">
jQuery
$(document).ready(function () {
$('#imgupload').change( function(event) {
var len = $('.img-remove').length;
if(len < 1){
$('.fileupload-wrp').append('<a class="img-remove" id="remvImg" style="" onclick="removeimg()" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="Remove Image"><i class="fa fa-trash"></i></a>');
}
});
}); //imgupload is the file upload id
对于每次上传,我都会附加删除按钮
移除点击事件
function removeimg(){
if(confirm("Are you sure you want to delete this?")){
$('#imgupload').val('');
$("#remvImg").remove();
}
}
【讨论】: