拖放jquery删除问题



我已经实现了这个拖放:http://hayageek.com/drag-and-drop-file-upload-jquery/.

它工作得很好,但是,我的问题是:

我添加一个文件,然后删除它。当我添加另一个文件"已删除"文件时,它再次出现,但没有删除按钮…

我非常想解决这个问题。

我认为问题要么在处理程序中要么在删除函数中。但是我找不到。也许我需要休息一下……

$(document).ready(function () {
$("#errorMessages").hide();
// Handle drag and drop events with jQuery
var obj = $("#dragandrophandler");
obj.on('dragenter', function (e) {
    e.stopPropagation();
    e.preventDefault();
    $(this).css('border', '2px solid #0B85A1');
});
obj.on('dragover', function (e) {
    e.stopPropagation();
    e.preventDefault();
});
obj.on('drop', function (e) {
    $(this).css('border', '2px dotted #0B85A1');
    e.preventDefault();
    var files = e.originalEvent.dataTransfer.files;
    cleanErrorMessages();
    //We need to send dropped files to Server
    handleFileUpload(files, obj, uploadURL);
});
// If the files are dropped outside the div, file is opened in the browser window. To avoid that we can prevent ‘drop’ event on document.
$(document).on('dragenter', function (e) {
    e.stopPropagation();
    e.preventDefault();
});
$(document).on('dragover', function (e) {
    e.stopPropagation();
    e.preventDefault();
    obj.css('border', '2px dotted #0B85A1');
});
$(document).on('drop', function (e) {
    e.stopPropagation();
    e.preventDefault();
});
$("#file").change(function () {
    cleanErrorMessages();
});
// add file to the list using the input
$("#addFile").click(function (evt) {
    evt.preventDefault();
    var files = $("#file")[0].files;
    handleFileUpload(files, obj);
    $("#file").val("");
    return false;
});

});

有更多的代码,但我认为问题一定在这一部分。如果我找到了解决办法,我也会贴出来的。

remove函数:

this.remove.click(function (evt) {
    // TO DO:  call to the WS to remove from the server 
    var numrow = evt.currentTarget.parentElement.attributes[1].value;
        evt.currentTarget.parentElement.removeChild(evt.currentTarget);
    $(".statusbar[numrow='" + numrow + "']").fadeOut(1000, "easeInOutCubic", function (evt) {
    });
});

更改删除功能:

this.remove.click(function (evt) {
    // TO DO:  call to the WS to remove from the server 
    var numrow = evt.currentTarget.parentElement.attributes[1].value;
        evt.currentTarget.parentElement.remove(evt.currentTarget);
    $(".statusbar[numrow='" + numrow + "']").fadeOut(1000, "easeInOutCubic", function (evt) {
    });
});

只需要将:evt.currentTarget.parentElement.removeChild(evt.currentTarget);改为:evt.currentTarget.parentElement.remove(evt.currentTarget);

最新更新