【发布时间】:2013-10-14 17:02:17
【问题描述】:
看到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 语句。我错过了什么?
【问题讨论】:
-
不要在
hasClass的参数中添加.。 -
如果我这样做,它实际上根本不会改变文本
-
你切换了 seeMore 类,但从不处理 seemore2
标签: jquery