Javascript Jquery删除未被激发

Javascript Jquery删除未被激发,javascript,jquery,html,file-upload,drag-and-drop,Javascript,Jquery,Html,File Upload,Drag And Drop,我需要启动drop部分,这样当用户删除一个文件时,它就会上传。但在我的密码里,不要开火 请给我这个代码的正确版本。这对我的项目非常重要。此代码取自另一个stackoverflow帖子。我在下面给出的代码中编辑了drop部分。 用户的回答将不胜感激 $.fn.dndhover = function(options) { return this.each(function() { var self = $(this); var collection = $

我需要启动drop部分,这样当用户删除一个文件时,它就会上传。但在我的密码里,不要开火

请给我这个代码的正确版本。这对我的项目非常重要。此代码取自另一个stackoverflow帖子。我在下面给出的代码中编辑了drop部分。 用户的回答将不胜感激

$.fn.dndhover = function(options) {

    return this.each(function() {

        var self = $(this);
        var collection = $();

        self.on('dragenter', function(event) {
            if (collection.length === 0) {
                self.trigger('dndHoverStart');
            }
            collection = collection.add(event.target);
        });

        self.on('dragleave', function(event) {
            /*
             * Firefox 3.6 fires the dragleave event on the previous element
             * before firing dragenter on the next one so we introduce a delay
             */
            setTimeout(function() {
                collection = collection.not(event.target);
                if (collection.length === 0) {
                    self.trigger('dndHoverEnd');
                }
            }, 1);
        });

        self.on('drop', function(event) {
            alert(event);
            self.trigger('dndHoverDrop');
        });
    });
};

$('.uploadDiv').dndhover().on({
    'dndHoverStart': function(event) {

        if(!$(".selectFile").hasClass("hide")){
            $(".selectFile").addClass("hide");
        }
        if($(".dropFile").hasClass("hide")){
            $(".dropFile").removeClass("hide");
        }

        event.stopPropagation();
        event.preventDefault();
        return false;
    },
    'dndHoverEnd': function(event) {

        if($(".selectFile").hasClass("hide")){
            $(".selectFile").removeClass("hide");
        }
        if(!$(".dropFile").hasClass("hide")){
            $(".dropFile").addClass("hide");
        }

        event.stopPropagation();
        event.preventDefault();
        return false;
    },
    'dndHoverDrop': function(event) {
        alert('dropped');
        if(!$(".selectFile").hasClass("hide")){
            $(".selectFile").addClass("hide");
        }
        if(!$(".dropFile").hasClass("hide")){
            $(".dropFile").addClass("hide");
        }
        event.preventDefault();  
        event.stopPropagation();
        return false;
    }
});
新代码:

$.fn.dndhover = function(options) {

        return this.each(function() {

            var self = $(this);
            var collection = $();

            self.on('dragenter', function(event) {
                if (collection.length === 0) {
                    self.trigger('dndDragEnter');
                }
                collection = collection.add(event.target);
            });

            self.on('dragleave', function(event) {
                /*
                 * Firefox 3.6 fires the dragleave event on the previous element
                 * before firing dragenter on the next one so we introduce a delay
                 */
                setTimeout(function() {
                    collection = collection.not(event.target);
                    if (collection.length === 0) {
                        self.trigger('dndDragLeave');
                    }
                }, 1);
            });

            self.on('dragover', function(event) {
                setTimeout(function() {
                    collection = collection.not(event.target);
                    if (collection.length === 0) {
                        self.trigger('dndDragOver');
                    }
                }, 1);
            });

            self.on('drop,dragdrop', function(event) {
                self.trigger('dndDragDrop');
            });
        });
    };

    $('.uploadDiv').dndhover().on({
        'dndDragEnter': function(event) {

            if(!$(".selectFile").hasClass("hide")){
                $(".selectFile").addClass("hide");
            }
            if($(".dropFile").hasClass("hide")){
                $(".dropFile").removeClass("hide");
            }

            event.stopPropagation();
        },
        'dndDragLeave': function(event) {

            if($(".selectFile").hasClass("hide")){
                $(".selectFile").removeClass("hide");
            }
            if(!$(".dropFile").hasClass("hide")){
                $(".dropFile").addClass("hide");
            }
        },
        'dndDragDrop': function(event) {
            alert('dropped');
            if(!$(".selectFile").hasClass("hide")){
                $(".selectFile").addClass("hide");
            }
            if(!$(".dropFile").hasClass("hide")){
                $(".dropFile").addClass("hide");
            }
            alert(event);
            event.preventDefault();
        },
        'dndDragOver': function(event) {
            if(!$(".selectFile").hasClass("hide")){
                $(".selectFile").addClass("hide");
            }
            if($(".dropFile").hasClass("hide")){
                $(".dropFile").removeClass("hide");
            }
            event.preventDefault();
        }
    });

尝试上载工作代码这是主代码。uploadDiv将触发DNDHOverdop。尝试此操作并共享您的浏览器详细信息。我已经使用了它并编写了一个新代码,请检查上面的内容。但它不起作用。请给我答复或评论中的工作代码。