开发者

Error with "this" in IE with jQuery plugin

I'm coding a plugin for jQuery which now works fine on every browser but IE. This is part of the code:

(function( $ ){
    $.fn.myPlugin = function(options) {

        var methods = {
            getFirstList: functio开发者_开发技巧n(el){
                return $("ul:first", el);
            }
        };

        return this.each(function(){
            ...
            var list = methods.getFirstList(this); 
            // "this" here refers to window or document in IE.
            ...
        });
    };
})( jQuery );

When I call the plugin ($("#myObject").myPlugin();), the keyword "this" is not refered to the DOM object, but to the window or document.

How do I fix this?


Try replacing this with $(this)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜