出于某种原因,当我尝试执行以下代码时遇到未捕获的类型错误。
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
预期的动画效果;所以函数没有定义。只需切换到普通版本即可。
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/