添加/删除输入字段动态显示错误计数由jquery为什么不能解决这个问题?

我有多个文件上传,这里我显示文件计数和文件大小(最大3GB)上传,而删除文件我无法更新剩余文件和文件大小的计数。

注意 :如果我删除并添加更多文件,那么也会显示错误的计数

在此处输入图像描述 这是代码

 

这是我的jquery / Javascript代码

 var SITE_URL = ""; var increaseFile = 2, filecheck = 1, filesize = 0, total_file_size = ''; function getFileName(fileobj) { checkfiles(); if (filesize > 3204448256) { alert('Your files contains more than 3GB..please upload upto 3GB') } if (filecheck == 2) { $("#div-file-" + $("#" + fileobj.id + "").attr('inc')).hide(); $("#file_labels_div").append('
'); increaseFile++; } else { $("#file_labels_div").html('
'); increaseFile = 2; filesize = 0; } } function checkfiles() { //file_names=''; file_names = ''; filesize = 0; filecheck = 1; for (fcheck = 0; fcheck 0) { var x = document.getElementById("input-file-" + fcheck); var txt = ""; myFile = "input-file-" + fcheck + ""; if ('files' in x) { //alert(x.files.length) if (x.files.length == 0) { txt = "Select one or more files."; } else { filecheck = 2; for (var i = 0; i < x.files.length; i++) { //txt += "
" + (i+1) + ". file
"; var file = x.files[i]; if ('name' in file) { // txt += "name: " + file.name + "
"; if (filesize > 3204448256) { $("#all-filenames").html(file_names); //alert("You have exceeded maximum allowed size 3GB") return true; } if ('size' in file) { var sizeInMB = (file.size / (1024 * 1024)).toFixed(2); } //alert(sizeInMB + 'MB'); // file_names+=''+file.name+' ('+sizeInMB+'MB)
'; file_names += '
' + file.name + ' (' + sizeInMB + 'MB)
'; } if ('size' in file) { // txt += "size: " + file.size + " bytes
"; filesize += file.size } } } } //file_names+='
'; //$( "span" ).remove( "#all-filenames" ); // $("#all-filenames").remove(); $("#all-filenames").html(file_names) // alert('>>>'+txt) } } var sizeInMB = (filesize / (1024 * 1024)).toFixed(2); total_file_size = (fcheck - 1) + " ATTACHMENTS / (" + (3000 - sizeInMB) + "MB REMAINING)"; // $("#div-file-"+fcheck).html(total_file_size) } function deletefile(filename, divname) { // alert('file name is'+filename+"divname"+divname) $('#' + filename).remove(); $(divname).remove(); checkfiles(); if (filecheck == 1) { $("#file_labels_div").html('
'); $('#image-upload').append('
'); increaseFile = 2; filesize = 0; } }

感谢所有建议这是工作小提琴代码

https://fiddle.jshell.net/vijayak7803/vt5b0exw/15/