Twitter bootstrap 一旦展开,如何将可折叠的“更多”更改为“更少”?

Twitter bootstrap 一旦展开,如何将可折叠的“更多”更改为“更少”?,twitter-bootstrap,bootstrap-4,Twitter Bootstrap,Bootstrap 4,这很有效。我可以单击“更多”展开并显示第二段。但奇怪的是,它还说得更多。是否有任何方法可以在展开后将其更改为更少?您可以使用以下条件更改innerHTML以切换文本: $a.点击功能{ var$this=$this; $this.toggleClassopen; 如果$this.hasClassopen{ $this.htmless。。。; }否则{ $this.htmlmore。。。; } }; 谢谢但是你的a没有指定的打开,它来自哪里?更新:我想你是通过$this.toggleClasso

这很有效。我可以单击“更多”展开并显示第二段。但奇怪的是,它还说得更多。是否有任何方法可以在展开后将其更改为更少?

您可以使用以下条件更改innerHTML以切换文本:

$a.点击功能{ var$this=$this; $this.toggleClassopen; 如果$this.hasClassopen{ $this.htmless。。。; }否则{ $this.htmlmore。。。; } };
谢谢但是你的a没有指定的打开,它来自哪里?更新:我想你是通过$this.toggleClassopen注入的;如果您能再解释一下,那就太好了。在函数顶部,单击按钮后,open类将通过$this.toggleClassopen;添加到a标记中;。这意味着每次单击a标记时,代码都会交替地向a标记添加一个open类或将其删除。完成这一部分后,条件工作就会发生,如果类存在或不存在,html文本就会发生更改。谢谢,我今天就来试试。遗憾的是,如果没有任何js,这不能直接用CSS来完成。没问题,在我的脑海中,我不认为这可以用CSS来完成,因为你需要有条件的工作来计算按钮是否被点击,然后再次点击以更改文本。我认为使用JavaScript是最明智的选择。此选项将适用于您正在尝试的内容,希望不会有任何问题。谢谢。一旦我能再次使用我的笔记本电脑,我今天就会试试。让你知道。干杯
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.</p>
<p class="collapse" id="collapseSpeed">It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</p>
<a data-toggle="collapse" href="#collapseSpeed" aria-expanded="false" aria-controls="collapseSpeed">more...</a>