如何使用 jQuery.noConflict();
为我的网站安装灯箱后,我的评论停止工作。我查看了代码,并将 中的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你的代码将从
$(selector) 到 $j(selector)
这里给出了很多例子
http://api.jquery.com/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/
需要仔细考虑的一件事是脚本加载顺序并注意 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.
现在
你可以使用 $('#id').css(...);
To your answer
Now you can use $('#id').css(...);
该错误可能导致其余代码未执行,
.overlay
不是函数意味着.overlay
不是函数,而$
> 工作正常。它只是意味着您试图在
.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.It simply means you are trying to call
.overlay
before it exists.