繁体   English   中英

为什么我的Javascript无法在WordPress上运行,但是在本地HTML上可以正常运行?

[英]Why won't my javascript work on WordPress but fine when doing locally HTML?

我有这个WordPress主题,但我无法使jQuery脚本正常工作,我尝试了所有内容,没有冲突模式,包括在footer.php中包括我自己的jQuery,并在queue.php中包括了jQuery在header.php中,包括了WordPress' jQuery等

当我不在WordPress主题中时,我所有的脚本都能正常工作。

我的网址是http://andreas-berg.dk/wordpress/ ,我的脚本位于脚本的最底部,现在我将jQuery硬编码到footer.php中,并将其从顶部删除,但没有成功。

有什么解决办法吗? 我已经把头发拉了好几个小时了。

这些是我的脚本:

!function( $ ) { 

    $(".dropbutton a").click(function () {
        $("#dropdown").slideToggle();
    });

    $('.scroll-button').hide().fadeIn(1000);

    $(".slide").mouseenter(function () {
        $(this).children().stop().slideDown(200);
    }).mouseleave(function () {
        $(this).children().stop().slideUp(200);
    });

    $('.nav-container a, .scroll-button a, .blocks a, .banner a, .text-right a').click(function () {
        $('html, body').animate({
            scrollTop: $($(this).attr('href')).offset().top - 60
        }, 800, 'easeOutQuint');
        return false;
    });

    offsetValue = 60;
    $('body').data().scrollspy.options.offset = offsetValue;
    // force scrollspy to recalculate the offsets to your targets
    $('body').data().scrollspy.process();

    $('body').scrollspy({
        target: '.nav-container'
    });

}( window.jQuery );

您的JQuery运行正常。 如果您检查您的conole,您会看到一些错误,例如

**1068** errors stating: Uncaught TypeError: Object #<Object> has no method 'easeOutQuint'

为此,您需要安装jQuery Easing Plugin

检查您的错误,您的JS不能仅仅因为您的代码中存在严重错误而无法运行。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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