jquery 我收到此消息“对象[对象Object]没有方法'on' ”

rfbsl7qr  于 2022-11-03  发布在  jQuery
关注(0)|答案(2)|浏览(126)

我收到这样的消息:
“对象[object Object]没有方法”on““
代码:

$(window).on('resize', function () {
    self.setDimensions();
});

我能做什么?我已经有jQuery 1.9了...

jhdbpxl9

jhdbpxl91#

请确保使用jQuery 1.7或更高版本
在1.7之前的版本中,可以将.on()替换为.bind()(如果不使用事件委托)。
最好的方法可能是升级到最新的jQuery版本- 1.9 ATM。

anauzrmj

anauzrmj2#

如果您已经包含了最新版本的jQuery,但它仍然显示没有on,那么这意味着some other library is overwriting $。要解决此问题,请尝试以下操作:

$.noConflict();
jQuery(document).ready(function($) {
    // Use $ here
    var self = mysterious();
    $(window).on("resize", function(){
        self.setDimensions();
    })
});

http://jsfiddle.net/DerekL/SUBGD/

相关问题