本文介绍了jQuery:单击更改按钮文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
看到在jquery中切换按钮文本后,我尝试重新创建在我的情况下,它似乎无法正常工作.
After seeing Toggling button text in jquery this question, I tried to re create it in my situation but can't seem to have it work.
这是我所做的工作的小提琴: http://jsfiddle.net/V4u5X/
Here is a fiddle of what I've done: 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语句.我想念什么?
It seems to only ever run the if statement once. What am I missing?
推荐答案
$('.SeeMore2').click(function(){
var $this = $(this);
$this.toggleClass('SeeMore2');
if($this.hasClass('SeeMore2')){
$this.text('See More');
} else {
$this.text('See Less');
}
});
这应该做到.您必须确保切换正确的班级并取出.".从hasClass
This should do it. You have to make sure you toggle the correct class and take out the "." from the hasClass
这篇关于jQuery:单击更改按钮文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!