未捕获的类型错误:$content.switchClass不是函数
Uncaught TypeError: $content.switchClass is not a function
在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"){
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>
相关文章:
- @Url.Content(“~”)不适用于localhost
- 节点,express应用程序返回text/javascript响应头(Content-Type),尽管设置了applic
- X-Content-Type-Options=nosniff解决方法
- 计算content中的数字总和使用Jquery可编辑文本
- 为什么不是't my css `content:`在多个浏览器中工作,并总体上提高跨浏览器兼容性
- Url.Content中的Url不匹配
- Ajax content for Twitter Bootstrap Popover
- 在jQuery中将所有
content 替换为 - content
- 如何在 l.Content 方法(Asp.net MVC 剃刀)中给出 Javascript 变量@Ur
- gulp-concat twice the content
- Content-Security-Policy for webapp in iframe
- jQuery UI不会加载到.button的$(“#content”).load页面上
- 在具有CONTENT标记的自定义元素中使用SELECT标记时出现问题
- Ember:使用this.get('controller.').content,find方法
- 在Ember模板中呈现{{content}}时出现问题
- 使用.content().get().nodevalue;后在firebug中获取类型错误;
- iframe - set Content Type header
- center content uniformly using em's
- app.render[TypeError:无法设置undefined的属性'content']在Node
- 未捕获的类型错误:$content.switchClass不是函数