jQuery.easing[jQuery.easing.def]不是一个函数。

25

当我查看控制台时,我遇到了以下错误:

jQuery.easing[jQuery.easing.def] is not a function

我正在尝试在WordPress上制作一个滑块。由于我正在本地主机上工作,因此无法准确显示出现的情况。但是,当滑块仅在WordPress之外的HTML文件中时,它可以正常工作。当在WordPress中时,它会给我报错。如果您对问题可能是什么有任何见解,将不胜感激。


8
发布你的代码。我们无法调试看不见的代码。 - Blender
1
这篇博客帮助了我,现在它对我起作用了:http://www.gilluminate.com/2011/06/06/jquery-easingjquery-easing-def-is-not-a-function/ - OlivierG
9个回答

54

为了节省大家的时间。打开您的jQuery缓动插件文件,并将代码包裹在以下内容中:

$(document).ready(function() {
  Code goes here...
});

1
只有在使用CommonJS/browserify时才会出现问题,但这个解决方案解决了它。 - texelate
打开你的Jquery缓动插件文件 -- 那个文件在哪里?它是随WordPress一起提供的还是需要手动安装?谢谢 :) - aequalsb
@aequalsb 在检查元素中,当错误被打印出来时,将鼠标悬停在文件名上,它会显示完整的路径。 - Lemures
1
有人知道为什么当我使用 $(document) 时它可以工作,但如果我使用 jQuery(document) 就不行吗? - Lemures
@Lemures,当代码未被呈现或没有URL查看错误时,我如何查看OP的错误...我认为你误解了...我是在为OP建议行动。 - aequalsb

25
请检查是否重复加载了jQuery。如果您已经手动将jQuery插入页脚,请尝试删除它。

这就是我的问题所在!October CMS的一个插件正在注入自己的jQuery,与我自己包含的jQuery并存。 - jahackbeth

21
问题是:
swing: function (x, t, b, c, d) {
    return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
}

在这个函数中,jQuery可能不等于jQuery,在其中应用了jQuery.extend(jQuery.easing,
  1. replace jQuery with $
  2. wrap code with

    (function($, undefined) {
      ...
    }) (jQuery);
    

7
你是否已经引入了jQuery缓动插件?类似于:
  <script src="http://code.jquery.com/jquery.min.js"></script>
  <script src="http://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.3/jquery.easing.min.js"></script>

在你的页面中?

是的,当我添加那个时,会出现一个ReferenceError: jQuery未定义的错误,然后是原始错误。 - Eric Goncalves
然后您还需要在缓动插件之前添加jQuery本身...我已经编辑了答案! - pna
1
jQuery未定义的错误已经消失,但原始错误仍然存在。 - Eric Goncalves

5
if(typeof jQuery.easing[jQuery.easing.def] == 'function'){
    return jQuery.easing[jQuery.easing.def](x, t, b, c, d);
}

尝试在easing.js的swing()函数上运行此代码


4
请将jquery.easing.1.3.js文件放在使用插件之前的head标签中,或者使用document.ready。

3
不要在头部声明脚本,在文档完全加载后通过jQuery的.getScript()函数调用它。
示例:
<script>
$( document ).ready(function() {
    $.getScript('path_to_script/easing_script_name.js');
});
</script>

错误是由于在完全加载缓动脚本之前调用了jQuery。

2

您是否正在导入jQuery缓动插件?或任何高于1.7.2的内容?

那么只需将其删除并使用以下内容:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.js"></script>

0

如果您在调用WordPress幻灯片插件的JavaScript之前调用jQuery或jQuery UI,则可能会发生这种情况。

这样解决了吗?

<script type="text/javascript"
        src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script type="text/javascript"
        src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.4/umd/popper.min.js"></script>
    <script type="text/javascript"
        src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/js/bootstrap.min.js"></script>
        <script type="text/javascript" src="/wordpress-slider-plugin.js"></script>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接