简体   繁体   English

如何使用 $.noConflict() 修复 Lightbox2 问题?

[英]How do I fix Lightbox2 problems using $.noConflict()?

I've imported images to my site.我已将图像导入我的网站。 I want to open these images with lightbox2.我想用 lightbox2 打开这些图片。 I've installed the lightbox2-drupalmodule and that works on my frontpage (www.chirowijkoersel.be), but it doesn't work on the pages where I imported images.我已经安装了 lightbox2-drupalmodule,它可以在我的首页 (www.chirowijkoersel.be) 上运行,但它在我导入图像的页面上不起作用。

Lightbox does work with Opera. Lightbox 确实适用于 Opera。 I've also noticed that the lightbox2-module adds a class to the images in Opera and on the frontpage with every other browser.我还注意到 lightbox2-module 将 class 添加到 Opera 中的图像和其他所有浏览器的首页上。

Links:链接:

Edit: I've done some research, and I think the problem is caused by the multiple use of $.编辑:我做了一些研究,我认为问题是由于多次使用 $. I can solve this by using $.noConflict().我可以通过使用 $.noConflict() 来解决这个问题。 But where do I need to put this?但是我需要把这个放在哪里?

it could be javascript conflicts?可能是 javascript 冲突?

You would put the $.noConflict() inside a script tag, right after you import jQuery.在导入 jQuery 之后,您可以将 $.noConflict() 放入脚本标记中。 So if you have something like:所以如果你有类似的东西:

<script src="jQuery.js"></script>

already, you'd just do:已经,你只需要做:

<script src="jQuery.js"></script>
<script>$.noConflict();</script>

Hope that helps.希望有帮助。

Wrap of you javascript, and use self invoking functions包装你 javascript,并使用自调用函数

(function($){

      /// Your page code here
      // Here you can use $ 
      // We are passing jquery as $ to this self invoking function.
})(jquery)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM