我的代码运行有点搞笑。如果您点击该链接,它应该从show more
转到show less
然后再次点击时应转到show more
,但行为不符合预期。
#theLink.collapsed:before
{
content:'Show less' ;
}
#theLink:before
{
content:'Show more' ;
}
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<a data-toggle="collapse" href="#intro" aria-expanded="false" aria-controls="intro" id="theLink"></a>
<div id="intro" class="collapse">
Here comes the text...
</div>
答案 0 :(得分:1)
您的more
和less
文字只是错误的方式。当链接具有show more
类时,需要显示collapsed
文本。
我还初始化了默认情况下collapsed
类的链接。
#theLink.collapsed:before
{
content:'Show more' ;
}
#theLink:before
{
content:'Show less' ;
}
&#13;
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<a class="collapsed" data-toggle="collapse" href="#intro" aria-expanded="false" aria-controls="intro" id="theLink"></a>
<div id="intro" class="collapse">
Here comes the text...
</div>
&#13;