我发现我的答案上的一部分:jQuery change button text更改按钮文本
改变对点击按钮的文字。我正在寻找的是如何切换该文本。我尝试使用类方法切换“show teams”/“隐藏团队”的文本。 如果我只是使用属性,我可以更改按钮上的文字点击,但不会改回它。
HTML
<input class="teams" type="button" value="Teams" />
JS
$(".teams").click(function() {
$("#container2").toggle();
//$("#teams").prop("value", "Hide Teams");
var $this = $(this);
if ($this.hasClass('teams')) {
$this.text('Show Teams');
} else {
$this.text('Hide Teams');
}
});
没错,但只有部分解决了这个问题。 – j08691
@ j08691是的..忘了切换课程了。 –