如何使用 jQuery.noConflict();

发布于 2024-12-28 16:48:39 字数 655 浏览 3 评论 0原文

为我的网站安装灯箱后,我的评论停止工作。我查看了代码,并将 中的 javascript 链接(lightbox 附带的链接)移动到了 Wordpress-Buddypress 附带的 javascript 链接上方。之前,我来自 Lightbox 的 javascript 链接位于 Wordpress 附带的 javascript 链接下方。

进行切换后,评论在我的网站上再次开始工作,但现在灯箱不起作用。

当我使用 Firebug 查找错误时,出现此错误。

$("#videogallery a[rel]").overlay is not a function

该代码来自“videolightbox.js”,这是我的灯箱附带的文件。

我对这个问题做了很多研究,我想我可能需要使用 jQuery.noConflict(); ,但我不知道如何使用它?我正在查看这个链接

但我可以'似乎无法让它工作,因为我不知道如何使用它。我还尝试用 jQuery() 替换所有 $() ,但这并没有解决我的问题。

After installing lightbox for my website my comments stopped working. I looked at the code and moved the javascript links that were in the <head> (the ones that came with lightbox) in the to above the javascript links that came with Wordpress-Buddypress. Before my javascript links from Lightbox were below the javascript links that came with Wordpress.

After making the switch, the comments started working again on my website but now the lightbox does not work.

When I use Firebug to find errors, I get this error.

$("#videogallery a[rel]").overlay is not a function

That code comes from "videolightbox.js" which was a file that came with my lightbox.

I did lots of reseach on this problem and I am thinking that I might need to use jQuery.noConflict(); but I have no idea how to use it? I was looking at this link

but I can't seem to get it to work because I have no idea how to use it. I also tried replacing all the $() with jQuery() but that did not solve my problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

权谋诡计 2025-01-04 16:48:39

但我不知道如何使用它?

var $j = jQuery.noConflict();

你的代码将从
$(selector) 到 $j(selector)

这里给出了很多例子
http://api.jquery.com/jQuery.noConflict/

but I have no idea how to use it?

var $j = jQuery.noConflict();

and your code will change from
$(selector) to $j(selector)

A lot of examples are given here
http://api.jquery.com/jQuery.noConflict/

丘比特射中我 2025-01-04 16:48:39

需要仔细考虑的一件事是脚本加载顺序并注意 JQuery 的重复加载。在某些(希望很少见)情况下,您可以加载 JQuery,设置一些使用它的代码,然后重新加载 JQuery,这会丢弃第一次加载后设置的事件。

我知道我曾经遇到过这种情况,但我不记得导致它发生的细节。

One thing to consider closely is the script loading order and watch for repeat loading of JQuery. In some (hopefully rare) situations, you can load JQuery, set up some code that uses it, then reload JQuery which tosses away the events that were set up after loading it the first time.

I know I ran into that situation once, but I can't remember the details that led to it occurring.

夜还是长夜 2025-01-04 16:48:39

现在

$=jQuery.noConflict();

你可以使用 $('#id').css(...);

To your answer

$=jQuery.noConflict();

Now you can use $('#id').css(...);

梦晓ヶ微光ヅ倾城 2025-01-04 16:48:39

该错误可能导致其余代码未执行,.overlay 不是函数意味着 .overlay 不是函数,而 $ > 工作正常。

var test; test("#videogallery a[rel]").test()
//TypeError: test is not a function <-- You would see this if $ wasn't working

var test = function(){return {};};
test("#videogallery a[rel]").test();
//TypeError: test("#videogallery a[rel]").test is not a function <-- You see this because .overlay isn't working

它只是意味着您试图在 .overlay 存在之前调用它。

The error is probably causing the rest of the code not being executed, .overlay is not a function means that .overlay is not a function and $ is working fine.

var test; test("#videogallery a[rel]").test()
//TypeError: test is not a function <-- You would see this if $ wasn't working

var test = function(){return {};};
test("#videogallery a[rel]").test();
//TypeError: test("#videogallery a[rel]").test is not a function <-- You see this because .overlay isn't working

It simply means you are trying to call .overlay before it exists.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文