在看到
Toggling button text in jquery这个问题后,我试图在我的情况下重新创建它,但似乎无法让它工作.
这是我所做的一个小提琴:http://jsfiddle.net/V4u5X/
$('.SeeMore2').click(function(){ var $this = $(this); $this.toggleClass('SeeMore'); if($this.hasClass('.SeeMore2')){ $this.text('See More'); } else { $this.text('See Less'); } });
它似乎只运行一次if语句.我错过了什么?
解决方法
$('.SeeMore2').click(function(){ var $this = $(this); $this.toggleClass('SeeMore2'); if($this.hasClass('SeeMore2')){ $this.text('See More'); } else { $this.text('See Less'); } });
这应该做到这一点.你必须确保切换正确的类并取出“.”.来自hasClass
原文地址:https://www.jb51.cc/jquery/181032.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。