Javascript / jQuery loading (conflict)

不想你离开。 提交于 2019-12-08 03:17:08

问题


I'm trying to load in a few jQuery files, a drupal 6 slideshow, flexslider carosel, modernize and a bootstrap modal.

I would just like to say I am including jquery from google cdn and putting a no conflict to load the flex slider - if I take the flexslider load away the Slideshow works. Weird.

<script type="text/javascript">
 $.noConflict();
 jQuery(window).load(function() {
  jQuery('.flexslider').flexslider({
  controlNav: false, 
    animation: "slide",
    animationLoop: false,
    itemWidth: 162,
    itemMargin: 5
  });
});
</script>

All are working fine, except the drupal 6 slideshow. It returns this error in chrome -

Uncaught TypeError: Property '$' of object [object Window] is not a function 

I know drupal 6 is bring in version 1.4 of jquery and I also have google 1.7 cdn in there, but I do have a no conflict bit of code working.

Any help on getting this slider to load would be much appreciated.

Side note -Any reason why modernizer is putting a very subtle light white background over my ENTIRE webpage?


回答1:


Most of the time, you don't need to use jQuerys noConflict option. When you use noConflict, $ sign is no more refers to jQuery and most plugins depending on the jQuery use $ to access it.

Your slide also wants to access Jquery via $ but you used noConflict and removed the reference that your plugin uses.

Just remove noConflict and you'll be fine.




回答2:


In your page header, the code below already exists.

<script>
    var jq17 = jQuery.noConflict();
</script>

So after that, you can't use $ as jQuery any more, instead, you should just use jq17.



来源:https://stackoverflow.com/questions/12111141/javascript-jquery-loading-conflict

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!