.slideToggle()在使用Jquery 3.1.1时不起作用 [英] .slideToggle() not working when using Jquery 3.1.1

查看:861
本文介绍了.slideToggle()在使用Jquery 3.1.1时不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于某种原因,当我尝试执行以下代码时,我得到一个Uncaught TypeError。

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

我得到以下错误:

<$ p $未知的TypeError:currentElement.slideToggle不是HTMLDivElement中的函数
。< anonymous> (index.js:6)
在HTMLDivElement.dispatch(jquery-3.1.1.slim.min.js:3)
在HTMLDivElement.q.handle(jquery-3.1.1.slim.min .js:3)

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



任何人都可以解释为什么这是?

slim 版本,它排除了像 slideToggle 所预期的动画效果 code>;所以函数没有定义。只需切换到正常版本即可。



Jquery Page
$ b


修身 < br>有时你不需要ajax,或者你更喜欢使用专注于ajax请求的独立库中的一个。对于所有的Web动画,通常使用CSS和类操作的组合更简单。除了包含ajax和效果模块的常规jQuery版本,我们还发布了一个排除这些模块的超薄版本。总而言之,它排除了Ajax,效果和当前已弃用的代码。



For some reason I am getting an Uncaught TypeError when I try and execute the following code.

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

I get the following error

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)

However when I call currentElement.toggle() It works as expected and I do not get any errors.

Can anyone explain why this is?

解决方案

The problem here is you are using the slim version which excludes the effects like the animation expected from slideToggle; so the function isn't defined. Just switch to the normal version.

From the 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.

这篇关于.slideToggle()在使用Jquery 3.1.1时不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆