拖放jquery删除问题

时间:2014-06-19 09:37:49

标签: jquery drag-and-drop

我已经实现了这个拖放: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;
});

});

代码更多,但我认为问题必须在这部分。如果我找到解决方案,我会发布它。

删除功能:

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) {
    });
});

1 个答案:

答案 0 :(得分:0)

更改了删除功能:

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);