Javascript 未捕获类型错误:$content.switchClass不是函数
Show more Show less在JavaScript代码中返回一个错误。我做错了什么 JS代码Javascript 未捕获类型错误:$content.switchClass不是函数,javascript,jquery,Javascript,Jquery,Show more Show less在JavaScript代码中返回一个错误。我做错了什么 JS代码 $(".show-more a").on("click", function() { var $this = $(this); var $content = $this.parent().prev("div.content"); var linkText = $this.text().toUpperCase(); if(linkText === "SHOW MORE"){
$(".show-more a").on("click", function() {
var $this = $(this);
var $content = $this.parent().prev("div.content");
var linkText = $this.text().toUpperCase();
if(linkText === "SHOW MORE"){
linkText = "Show less";
$content.switchClass("hideContent", "showContent", 400);
} else {
linkText = "Show more";
$content.switchClass("showContent", "hideContent", 400);
};
$this.text(linkText);
});
控制台错误
Uncaught TypeError: $content.switchClass is not a function
包含的脚本标记
<script src="//code.jquery.com/jquery.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="js/main.js"></script>
您很可能缺少jQuery UI,因为switchClass是jQuery UI的一部分,而不是jQuery库。正如其他人所说,您缺少jQuery UI。您的脚本标记应如下所示:
<script src="//code.jquery.com/jquery.js"></script>
<script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="js/main.js"></script>
是否包含jQuery UI?jQuery没有switchClass
,jQuery UI有。请附加jQuery UI脚本(例如),然后重试。应该可以工作^我看不到jQuery UI,每个人都告诉你你缺少它。是的,它解决了这个问题。但是效果消失了,欢迎你,艾哈迈特·伊斯拉姆。如果您对响应满意,请将其标记为已回答:-)为什么要用中性的/
加载所有lib,用http
加载jQuery UI?没有原因,我只是从地址栏抓取了它