gpt4 book ai didi

javascript - WordPress 中的 "Uncaught TypeError: $ is not a function"

转载 作者:行者123 更新时间:2023-11-30 07:20:48 24 4
gpt4 key购买 nike

<分区>

关于这个错误有一些问题,但我找不到任何解决方案。我正在开发一个 WordPress 主题,在排队脚本期间出现了这个错误:

Uncaught TypeError: $ is not a function
at components.js?ver=4.8:65
at components.js?ver=4.8:95

这是我添加到 functions.php 的排队代码:

function goc_scripts() {
wp_enqueue_style( 'goc-style', get_stylesheet_uri() );

wp_enqueue_style( 'socicon', get_stylesheet_directory_uri() . '/css/socicon.css', array() );

wp_enqueue_style( 'bootstrap-social', get_stylesheet_directory_uri() . '/css/bootstrap-social.css', array() );

wp_enqueue_style('bootstrap', get_template_directory_uri() . '/css/bootstrap.min.css');

wp_enqueue_style('font-awesome', get_template_directory_uri() . '/css/font-awesome.min.css');

wp_enqueue_style('simple-line-icons', get_template_directory_uri() . '/css/simple-line-icons.min.css');

wp_enqueue_style('animate', get_template_directory_uri() . '/css/animate.min.css');

wp_enqueue_style('cubeportfolio', get_template_directory_uri() . '/css/cubeportfolio.min.css');

wp_enqueue_style( 'owlcarousel-style', get_template_directory_uri() . '/css/owl.carousel.css' );

wp_enqueue_style( 'fancybox', get_template_directory_uri() . '/css/jquery.fancybox.css' );

wp_enqueue_style( 'goc-slider', get_template_directory_uri() . '/css/slider.css' );

wp_enqueue_style( 'goc-plugins', get_template_directory_uri() . '/css/plugins.css' );

wp_enqueue_style( 'goc-red3', get_template_directory_uri() . '/css/themes/red3.css' );

wp_enqueue_style( 'goc-custom', get_template_directory_uri() . '/css/custom.css' );

wp_enqueue_script( 'goc-jquery-min', get_template_directory_uri() . '/js/jquery.min.js', array(), false, true );

wp_enqueue_script( 'goc-jquery-migrate', get_template_directory_uri() . '/js/jquery-migrate.min.js', array(), false, true );

wp_enqueue_script( 'goc-jquery-easing', get_template_directory_uri() . '/js/jquery.easing.min.js', array(), false, true );

wp_enqueue_script( 'goc-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20151215', true );

wp_enqueue_script( 'goc-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20151215', true );

wp_enqueue_script( 'bootstrap-js', '//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js', array(jquery), true); // prueba

wp_enqueue_script( 'goc-reveal-animate', get_template_directory_uri() . '/js/reveal-animate.js', array(), '4.8', true );

wp_enqueue_script( 'goc-reveal-animate-wow', get_template_directory_uri() . '/js/reveal-animate/wow.js', array(), false, true );

wp_enqueue_script( 'goc-cubeportfolio', get_template_directory_uri() . '/js/cubeportfolio/js/jquery.cubeportfolio.min.js', array(), false, true );

wp_enqueue_script( 'goc-owl-carousel', get_template_directory_uri() . '/js/owl-carousel/owl.carousel.min.js', array(), false, true );

wp_enqueue_script( 'goc-counterup', get_template_directory_uri() . '/js/counterup/jquery.counterup.min.js', array(), false, true );

wp_enqueue_script( 'goc-waypoints', get_template_directory_uri() . '/js/counterup/jquery.waypoints.min.js', array(), false, true );

wp_enqueue_script( 'goc-fancybox', get_template_directory_uri() . '/js/fancybox/jquery.fancybox.pack.js', array(), false, true );

wp_enqueue_script( 'goc-jquery.smooth-scroll', get_template_directory_uri() . '/js/smooth-scroll/jquery.smooth-scroll.js', array(), false, true );

wp_enqueue_script( 'goc-slider', get_template_directory_uri() . '/js/slider-for-bootstrap/js/bootstrap-slider.js', array(jquery), false, true );

wp_enqueue_script( 'goc-component', get_template_directory_uri() . '/js/components.js', array(jquery), '4.8', false );

wp_enqueue_script( 'goc-components', get_template_directory_uri() . '/js/components-shop.js', array(), '4.8', true );

wp_enqueue_script( 'goc-appjs', get_template_directory_uri() . '/js/app.js', array(), false, true );

if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
}
add_action( 'wp_enqueue_scripts', 'goc_scripts' );

这是发生错误的代码 components.js(第 65 行和第 95 行):

var LayoutHeader = function () {
var offset = parseInt($('.c-layout-header').attr('data-minimize-offset') > 0 ? parseInt($('.c-layout-header').attr('data-minimize-offset')) : 0);
var _handleHeaderOnScroll = function () {
if ($(window).scrollTop() > offset) {
$("body").addClass("c-page-on-scroll");
} else {
$("body").removeClass("c-page-on-scroll");
}
}

var _handleTopbarCollapse = function () {
$('.c-layout-header .c-topbar-toggler').on('click', function (e) {
$('.c-layout-header-topbar-collapse').toggleClass("c-topbar-expanded");
});
}

return {
//main function to initiate the module
init: function () {
if ($('body').hasClass('c-layout-header-fixed-non-minimized')) {
return;
}

_handleHeaderOnScroll();
_handleTopbarCollapse();

$(window).scroll(function () {
_handleHeaderOnScroll();
});
}
};
}();

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com