Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/475.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/237.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript WordPress错误:$(…)。即使在JS文件排队后,carousel也不是一个函数_Javascript_Php_Jquery_Wordpress - Fatal编程技术网

Javascript WordPress错误:$(…)。即使在JS文件排队后,carousel也不是一个函数

Javascript WordPress错误:$(…)。即使在JS文件排队后,carousel也不是一个函数,javascript,php,jquery,wordpress,Javascript,Php,Jquery,Wordpress,就我的一生而言,我无法理解为什么我总是犯这样的错误。JS脚本没有排队,console.log测试会显示在浏览器中,如下所示 未捕获类型错误:$(…)。旋转木马不是函数 请参阅下面的JS和Functions.php代码 Carousel JS code:我把它放到了语法检查器中,它说没问题 var $ = jQuery; //This fixed the WordPress error “Uncaught TypeError: $ is not a function” $(document)

就我的一生而言,我无法理解为什么我总是犯这样的错误。JS脚本没有排队,console.log测试会显示在浏览器中,如下所示

未捕获类型错误:$(…)。旋转木马不是函数

请参阅下面的JS和Functions.php代码

Carousel JS code:我把它放到了语法检查器中,它说没问题

var $ = jQuery; //This fixed the WordPress error “Uncaught TypeError: $ is not a function” 

$(document).ready(function() {

    console.log( "Testing blog-tab-carousel.js file. It is properly enqueued." );

    var clickEvent = false;
    $('#newsCarousel').carousel({
     interval: 4000
    }).on('click', '.list-group li', function() {
     clickEvent = true;
     $('.list-group li').removeClass('active');
     $(this).addClass('active');
    }).on('slid.bs.carousel', function(e) {
     if (!clickEvent) {
      var count = $('.list-group').children().length - 1;
      var current = $('.list-group li.active');
      current.removeClass('active').next().addClass('active');
      var id = parseInt(current.data('slide-to'));
      if (count == id) {
       $('.list-group li').first().addClass('active');
      }
     }
     clickEvent = false;
    });
   })

   $(window).load(function() {
    var boxheight = $('#newsCarousel .carousel-inner').innerHeight();
    var itemlength = $('#newsCarousel .item').length;
    var triggerheight = Math.round(boxheight / itemlength + 1);
    $('#newsCarousel .list-group-item').outerHeight(triggerheight);
   });
Functions.php相关代码段

function enqueue_blog_custom_styles() {
    wp_enqueue_style( 'blog-tab-carousel', '/wp-content/themes/kiddieacademy/css/blog-tab-carousel.css', false ); 
}

add_action( 'wp_enqueue_scripts', 'enqueue_blog_custom_styles' );

function enqueue_blog_custom_script() {
    wp_enqueue_script( 'blog-tab-carousel', '/wp-content/themes/kiddieacademy/js/custom/blog-tab-carousel.js', false );
}

add_action( 'wp_enqueue_scripts', 'enqueue_blog_custom_script' );
注意:原始开发人员在functions.php中注销了jQuery。我注意到,当我对它进行注释时,博客转盘的console.log测试确实显示在控制台中。如果删除注释,保留wp_注销_脚本('jquery');那么console.log将不会显示

function enqueue_theme_scripts() {
    /* Remove the jquery script
     wp_deregister_script('jquery');  */
    require_js("mousewheel");
    require_js("fancybox");
}

我经常发现,在一个站点上重新定义$的方法在其他站点上是行不通的。就我个人而言,我使用它,而且它大多数时候都有效:

jQuery(document).ready(function($) {
    var $ = jQuery; // probably not needed, but seems to help in a "belt & braces" kinda way!

这个问题现在已经解决了。原来原来的开发公司没有将引导和CSS脚本排队,所以旋转木马无法工作。我必须下载物理文件并将其放在多站点层次结构中的主题文件夹中

谢谢大家的努力


您现在可以关闭此功能。

您是否在jQuery文件include之后包含转盘的插件文件?@Taplar这是WordPress我理解,但他的第一行是全局范围内的
var$=jQuery
@KevinBNo,因为他们的站点文件中有一个jQueryV1.12.4JS文件。我应该吗?好的,那么他们的文件包括jQuery、jQuery迁移(从您的屏幕截图)和他们的逻辑?这是因为您的min js文件是在脚本之后加载的,这是唯一的问题。谢谢,但我认为您不明白我的意思。我现在好了。