简体   繁体   中英

Bootstrap dropdown menu jQuery conflicts with other libraries?

I have installed some jQuery components on my website , a Bootstrap dropdown menu, a banner slider and a content slider.

Currently the dropdown menu doesn't work while the banner slider & content slider works fine. I have tried to disable the jQuery link from the content slider (which made the dropdown menu back to work), so I know they're conflicting.

The dropdown menu jQuery is located here:

<script src="http://www.helpmyedu.com/wp-content/themes/parallelus-moxie/assets/js/jquery.js"></script>

And the content slider jQuery is located here:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

How can I combine them two?

Thanks

=======UPDATE====================================================

I for some reason deleted the line:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

And everything worked......

Thanks guys!

See Console Error

在此处输入图片说明

Remove this code and your drop-down will work fine.


Are you including Plugin file of twitter-bootstrap-hover-dropdown
If you want to show menu on hover

see Fiddle DEMO

I think you don't need to call same scripts.

<script src="http://www.helpmyedu.com/wp-content/themes/parallelus-moxie/assets/js/jquery.js"></script>
/*! jQuery v1.10.2 | (c) 2005, 2013 jQuery Foundation, Inc. | jquery.org/license
//@ sourceMappingURL=jquery-1.10.2.min.map
*/

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
/*! jQuery v1.10.2 | (c) 2005, 2013 jQuery Foundation, Inc. | jquery.org/license
//@ sourceMappingURL=jquery.min.map
*/

They are of different sources but both jQuery v1.10.2. Just use one and put that over the other javascript you are using.

NOTE : My answer is based on:

Currently the dropdown menu doesn't work while the banner slider & content slider works fine. I have tried to disable the jQuery link from the content slider (which made the dropdown menu back to work), so I know they're conflicting.

Base on your source url provided above, you have something like this in your mark up:

<!-- jQuery #1 --><script src="http://www.helpmyedu.com/wp-content/themes/parallelus-moxie/assets/js/jquery.js"></script>
<script src="http://www.helpmyedu.com/wp-content/themes/parallelus-moxie/assets/js/twitter-bootstrap-hover-dropdown.js"></script>
<script>
// very simple to use!
$(document).ready(function() {
  $('.js-activated').dropdownHover().dropdown();
});
</script>

<!-- CSS Embedded Here.. -->

<!-- jQuery #2 --><script type='text/javascript' src='http://www.helpmyedu.com/wp-includes/js/jquery/jquery.js?ver=1.10.2'></script>
<script type='text/javascript' src='http://www.helpmyedu.com/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.2.1'></script>
<script type='text/javascript' src='http://www.helpmyedu.com/wp-content/plugins/alligator-popup/js/popup.js?ver=1.0.0'></script>
<script type='text/javascript' src='http://www.helpmyedu.com/wp-content/plugins/iphorm-form-builder/js/iphorm.js?ver=1.4.4'></script>
<script type='text/javascript' src='http://www.helpmyedu.com/wp-includes/js/swfupload/swfupload.js?ver=2201-20110113'></script>
<script type='text/javascript' src='http://www.helpmyedu.com/wp-includes/js/swfobject.js?ver=2.2-20120417'></script>
<script type='text/javascript' src='http://www.helpmyedu.com/wp-includes/js/swfupload/plugins/swfupload.swfobject.js?ver=2201a'></script>
<script type='text/javascript' src='http://www.helpmyedu.com/wp-includes/js/swfupload/plugins/swfupload.queue.js?ver=2201'></script>
<script type='text/javascript' src='http://www.helpmyedu.com/wp-content/plugins/revslider/rs-plugin/js/jquery.themepunch.plugins.min.js?ver=3.7.1'></script>
<script type='text/javascript' src='http://www.helpmyedu.com/wp-content/plugins/revslider/rs-plugin/js/jquery.themepunch.revolution.min.js?ver=3.7.1'></script>
<script type='text/javascript' src='http://www.helpmyedu.com/wp-content/themes/parallelus-moxie/assets/js/modernizr-2.6.2-respond-1.1.0.min.js?ver=2.6.2'></script>

I think you must remove the jQuery#1 and move the other 2 scripts together with the others below like this:

<!-- CSS Embedded Here.. -->

<!-- jQuery #2 --><script type='text/javascript' src='http://www.helpmyedu.com/wp-includes/js/jquery/jquery.js?ver=1.10.2'></script>
<script src="http://www.helpmyedu.com/wp-content/themes/parallelus-moxie/assets/js/twitter-bootstrap-hover-dropdown.js"></script>
<script>
// very simple to use!
$(document).ready(function() {
  $('.js-activated').dropdownHover().dropdown();
});
</script>

<script type='text/javascript' src='http://www.helpmyedu.com/wp-includes/js/jquery/jquery-migrate.min.js?ver=1.2.1'></script>
<script type='text/javascript' src='http://www.helpmyedu.com/wp-content/plugins/alligator-popup/js/popup.js?ver=1.0.0'></script>
<script type='text/javascript' src='http://www.helpmyedu.com/wp-content/plugins/iphorm-form-builder/js/iphorm.js?ver=1.4.4'></script>
<script type='text/javascript' src='http://www.helpmyedu.com/wp-includes/js/swfupload/swfupload.js?ver=2201-20110113'></script>
<script type='text/javascript' src='http://www.helpmyedu.com/wp-includes/js/swfobject.js?ver=2.2-20120417'></script>
<script type='text/javascript' src='http://www.helpmyedu.com/wp-includes/js/swfupload/plugins/swfupload.swfobject.js?ver=2201a'></script>
<script type='text/javascript' src='http://www.helpmyedu.com/wp-includes/js/swfupload/plugins/swfupload.queue.js?ver=2201'></script>
<script type='text/javascript' src='http://www.helpmyedu.com/wp-content/plugins/revslider/rs-plugin/js/jquery.themepunch.plugins.min.js?ver=3.7.1'></script>
<script type='text/javascript' src='http://www.helpmyedu.com/wp-content/plugins/revslider/rs-plugin/js/jquery.themepunch.revolution.min.js?ver=3.7.1'></script>
<script type='text/javascript' src='http://www.helpmyedu.com/wp-content/themes/parallelus-moxie/assets/js/modernizr-2.6.2-respond-1.1.0.min.js?ver=2.6.2'></script>

The problem is that your resources are not loading properly on the initial page load that is why your drop downs are not working. I have not made a Wordpress theme in a while. But if you are making a theme to use within wordpress mostly all of your content for the theme should primarily be located in 'content/themes/"the name of your theme"'.

You have a folder called asdtest that has an index file that is testing for an initialization the drop-down hover then you are calling dropdown() remove that like so.

$('.js-activated').dropdownHover();

The docs says you can use either javascript or data-attributes to make it work so pick one method and now you are trying both.

I am trying to pin point it but i think your problems are in the structure of the wordpress theme folder and how that index page is being use initially. Trying to look around and see what is stopping your resources from loading and i think you may be good.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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