我收到这样的消息:“对象[object Object]没有方法”on““代码:
$(window).on('resize', function () { self.setDimensions(); });
我能做什么?我已经有jQuery 1.9了...
jhdbpxl91#
请确保使用jQuery 1.7或更高版本在1.7之前的版本中,可以将.on()替换为.bind()(如果不使用事件委托)。最好的方法可能是升级到最新的jQuery版本- 1.9 ATM。
.on()
.bind()
anauzrmj2#
如果您已经包含了最新版本的jQuery,但它仍然显示没有on,那么这意味着some other library is overwriting $。要解决此问题,请尝试以下操作:
on
$
$.noConflict(); jQuery(document).ready(function($) { // Use $ here var self = mysterious(); $(window).on("resize", function(){ self.setDimensions(); }) });
http://jsfiddle.net/DerekL/SUBGD/
2条答案
按热度按时间jhdbpxl91#
请确保使用jQuery 1.7或更高版本
在1.7之前的版本中,可以将
.on()
替换为.bind()
(如果不使用事件委托)。最好的方法可能是升级到最新的jQuery版本- 1.9 ATM。
anauzrmj2#
如果您已经包含了最新版本的jQuery,但它仍然显示没有
on
,那么这意味着some other library is overwriting$
。要解决此问题,请尝试以下操作:http://jsfiddle.net/DerekL/SUBGD/