看到Toggling button text in jquery这个问题后,我试图在我的情况下重新创建它,但似乎无法工作。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'一个'.'。 – Barmar
如果我这样做,它实际上不会改变文本 – Scherf
您切换seeMore类,但从来没有处理seemore2 –