[英]jQuery Error: Uncaught TypeError: $ is not a function
I am having this issue due to using some third party script that is throwing me an error.由于使用了一些向我抛出错误的第三方脚本,我遇到了这个问题。 The script relates to a wordpress plugin that has actually been published by the author.
该脚本与作者实际发布的 wordpress 插件有关。
I am using the 'iLightBox' plugin to display liteboxes for my images.我正在使用“iLightBox”插件来显示我的图像的 liteboxes。 However i need to set which images appear in the lightbox gallery.
但是我需要设置哪些图像出现在灯箱库中。 I have been using the developer website and found the following URL: http://www.ilightbox.net/faq.html
我一直在使用开发者网站,发现如下网址: http : //www.ilightbox.net/faq.html
Script 5 appears to do what i need:脚本 5 似乎可以满足我的需要:
jQuery(document).ready(function(){
(function(){
var groupsArr = [];
$('[rel^="ilightbox["]').each(function () {
var group = this.getAttribute("rel");
$.inArray(group, groupsArr) === -1 && groupsArr.push(group);
});
$.each(groupsArr, function (i, groupName) {
$('[rel="' + groupName + '"]').iLightBox({ /* options */ });
});
})();
});
I am running this code in a custom.js file and i can see using 'inspect element' in Chrome that the file is loading correctly but the script is erroring with the following:我在 custom.js 文件中运行此代码,我可以在 Chrome 中使用“检查元素”看到该文件正在正确加载,但脚本出现以下错误:
"Uncaught TypeError: $ is not a function". “未捕获的类型错误:$ 不是函数”。
I have read through some posts by other users who explain i need to encapsulate with a function and finish with '(jQuery)' however if i do this it just generates more errors.我已经阅读了其他用户的一些帖子,他们解释说我需要用一个函数封装并用 '(jQuery)' 结束,但是如果我这样做,它只会产生更多的错误。
Can anyone assist me?任何人都可以帮助我吗?
My website where the error is showing: http://www.complete-models.com/uncategorized/16-alien-figure/我的网站显示错误: http : //www.complete-models.com/uncategorized/16-alien-figure/
If you can change your code just replace $
to jQuery
如果您可以更改代码,只需将
$
替换为jQuery
$('[rel^="ilightbox["]').each(function () {
to到
jQuery('[rel^="ilightbox["]').each(function () {
确保在jQuery
之后加载custom.js
,因此在 html 文件中,jQuery 的<scipt>
标签应该在custom.js
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.