未捕获的TypeError:$(...).ready不是函数

编程入门 行业动态 更新时间:2024-10-28 05:14:03
本文介绍了未捕获的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不是函数

本文发布于:2023-11-23 03:45:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1619968.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   TypeError   ready

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!