javascript - .slideToggle() 在使用 Jquery 3.1.1 时不起作用

标签 javascript jquery html jquery-ui

出于某种原因,当我尝试执行以下代码时遇到未捕获的类型错误。

jQuery(function($){
    $(document).ready(function() {
        $(".block").click(function() {
            var currentElement = $(this).find(".form-group");
            currentElement.slideToggle("slow");
        });
    });
});

出现以下错误

Uncaught TypeError: currentElement.slideToggle is not a function
at HTMLDivElement.<anonymous> (index.js:6)
at HTMLDivElement.dispatch (jquery-3.1.1.slim.min.js:3)
at HTMLDivElement.q.handle (jquery-3.1.1.slim.min.js:3)

然而,当我调用 currentElement.toggle() 时,它按预期工作,我没有收到任何错误。

谁能解释这是为什么?

最佳答案

这里的问题是您使用的是 slim 版本,它排除了 slideToggle 预期的动画效果;所以函数没有定义。只需切换到普通版本即可。

来自Jquery Page

Slim build

Sometimes you don’t need ajax, or you prefer to use one of the many standalone libraries that focus on ajax requests. And often it is simpler to use a combination of CSS and class manipulation for all your web animations. Along with the regular version of jQuery that includes the ajax and effects modules, we’ve released a “slim” version that excludes these modules. All in all, it excludes ajax, effects, and currently deprecated code.

关于javascript - .slideToggle() 在使用 Jquery 3.1.1 时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42653512/

相关文章:

javascript - 使用 Javascript 验证同一表单中的两个不同输入字段

javascript - IIFE 运行函数声明和函数表达式,结果不同

javascript - 根据键值显示 JSON 文件中的值

javascript - 将 UTC 字符串转换为 yyyy-mm-dd

jQuery隐藏所有具有相同id的元素

javascript - 为什么 JavaScript 原始变量不可变而对象变量不可变?

javascript - 我怎么知道 3D Secure 2 身份验证在升级到 stripe.js 版本 3 后有效

javascript - Angularjs 表单提交和导航到其他页面

html - Chrome iPhone 6 模拟器 100% 宽度比设备宽

Javascript 按钮和 document.location