简体   繁体   中英

Why doesn't ondragover work in a jQuery plugin?

I followed a tutorial on making a file uploader using javascript, and I got it to work and so I thought it would be better as a jQuery plugin so that I can use it on different elements on my page. So I started porting the code over to my plugin, and run into a problem.

Normally you can use jQuery and javascript, but for some reason ondragover is not working in my plugin.

;(function($) {
    "use strict";
    $.fn.asiLoader = function() {
        var base=$(this);

        base.ondragover=function(){
                alert('test');
                return false;
        }
        return base;
    }
})(jQuery);

I know I can use

base.on("dragover", function(e) {
   alert('test');
     e.preventDefault(); 
     e.stopPropagation();
});

instead, and that works and is the jQuery equivalent, but I want to know why the javascript isn't working?

base=$(this)是一个jQuery对象,而jQuery对象没有.dragover属性,但是DOM对象具有。

我认为你应该使用

base.dragover(function(){})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM