[英]Cancel one file to upload jQuery
With id="cancel_upload"
I want to delete one file in the queue to upload with jQuery, is there a way to do this? 使用id="cancel_upload"
我想删除队列中要使用jQuery上传的一个文件,有没有办法做到这一点? this is my code: 这是我的代码:
$("#files").on("change", function() {
var fp = $("#files");
var lg = fp[0].files.length;
var items = fp[0].files;
var fragment = "";
if (lg > 4) {
alert('Upload maksimal 4 file!');
return false;
} else {
$("#list_file").show();
for (var i = 0; i < lg; i++) {
var fileName = items[i].name;
var fileSize = items[i].size;
fragment += '<div class="item">' + '<a class="ui label">' + "(" + formatFileSize(fileSize) + ") " + fileName + '<i class="delete icon" id="cancel_upload"></i>' + "</a>" + "</div>" + "<br>";
}
$("#list_file").append(fragment);
$("#files").prop('disabled', true);
}
});
$("cancel_upload").on('click', function() {
fileName.abort();
});
Try something like 尝试类似
var ajaxCalll; $("#files").on("change", function() { var fp = $("#files"); var lg = fp[0].files.length; var items = fp[0].files; var fragment = ""; if (lg > 4) { alert('Upload maksimal 4 file!'); return false; } else { $("#list_file").show(); for (var i = 0; i < lg; i++) { var fileName = items[i].name; var fileSize = items[i].size; fragment += '<div class="item">' + '<a class="ui label">' + "(" + formatFileSize(fileSize) + ") " + fileName + '<i class="delete icon" id="cancel_upload"></i>' + "</a>" + "</div>" + "<br>"; } $("#list_file").append(fragment); $("#files").prop('disabled', true); // assign AJAX Call to ajaxCalll variable } }); $("#cancel_upload").on('click', function() { ajaxCalll.abort(); });
Hope this will help you. 希望这会帮助你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.