未捕获的TypeError:$(...).ready不是函数 [英] Uncaught TypeError: $(...).ready is not a function
本文介绍了未捕获的TypeError:$(...).ready不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道这已经被问过了,但是这里没有答案似乎对我有帮助.
Hi I Know this has been asked before but no answer on here seems to help me.
我有这块JS:
$(document).ready(function() {
$('.play-icon-hover').hover(function() {
$('.cms-model-banner-overlay').addClass('.cms-model-banner-overlay-active');
}, function() {
$('.cms-model-banner-overlay').removeClass('.cms-model-banner-overlay-active');
});
});
我似乎收到此错误,但我不知道为什么?
And I seem to be getting this error but I have no idea why?
Uncaught TypeError: $(...).ready is not a function
谢谢
推荐答案
您正在使用 Prototype.js
和 jQuery.js
.如果您想使用jQuery,最好将代码封装在IIFE中,如下所示:
You are using Prototype.js
as well as jQuery.js
. If you wanna use jQuery, it is better to encapsulate your code inside an IIFE like this:
(function ($) {
// jQuery code using $
})(jQuery);
因此,解决此问题的方法是将 $
更改为jQuery:
So the solution for your issue is either you change $
to jQuery:
jQuery(document).ready(function() {
jQuery('.play-icon-hover').hover(function() {
jQuery('.cms-model-banner-overlay').addClass('.cms-model-banner-overlay-active');
}, function() {
jQuery('.cms-model-banner-overlay').removeClass('.cms-model-banner-overlay-active');
});
});
或者,使用IIFE:
(function ($) {
$(document).ready(function() {
$('.play-icon-hover').hover(function() {
$('.cms-model-banner-overlay').addClass('.cms-model-banner-overlay-active');
}, function() {
$('.cms-model-banner-overlay').removeClass('.cms-model-banner-overlay-active');
});
});
})(jQuery);
这篇关于未捕获的TypeError:$(...).ready不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文