有人可以解释一下这个 jQuery 切换文本的方法吗?

Can someone explain this jQuery toggle text method please?

我在网上找到了这段代码并且运行良好,我有点了解它是如何工作的,但我想了解更多信息。

$(this).text($(this).text() == 'Read More' ? 'Read Less' : 'Read More');

拜托,谢谢!

您似乎对 ternary operator ? :

感到困惑

这是 if else 的简写形式。您显示的代码

$(this).text($(this).text() == 'Read More' ? 'Read Less' : 'Read More');

等于

if($(this).text() == 'Read More') {
  $(this).text('Read Less');
}else {
  $(this).text('Read More');
}