conflit jquery wordpress bootstrap

2019-09-01 06:15发布

I am using bootstrap into a WordPress theme and I have a conflict between jQuery in wp-include folder and my theme jQuery

this is my function jQuery that need bootstrap.min.js and jquery.js

jQuery(function($) {'use strict',

//#main-slider
$(function(){
    $('#main-slider.carousel').carousel({
        interval: 8000
    });
}); 
});

how could I resolve this problem ?

3条回答
劳资没心,怎么记你
2楼-- · 2019-09-01 06:46

Your code is messy and your redefining what the $ symbol means.

If you actually wish to redefine the jQuery $ you can use the .noConflict method.

jQuery.noConflict();

Make sure your selector is also correct #main-slider.carousel would select an element that looks like the following <div id="main-slider" class="carousel">. The selector #main-slider would achieve the same result.

I suggest you include some HTML in your question. Failing that the code below is my best attempt to answer.

Try the following:

'use strict';
jQuery.noConflict(); // If you wish to remove the jQuery '$'.
jQuery(function(){
   jQuery('#main-slider').carousel({
       interval: 8000
   });
}); 
查看更多
走好不送
3楼-- · 2019-09-01 07:07

You have to put jQuery into no-conflict mode to use it along with other JS libraries. For example:

var $j = jQuery.noConflict();
// $j is an alias to the jQuery function

$j(document).ready(function() {
    // ...
});
查看更多
虎瘦雄心在
4楼-- · 2019-09-01 07:08

The easiest way for one script is:

(function($){
    $(function()){
        //yours code
    });
}(jQuery));
查看更多
登录 后发表回答