【问题标题】:How to use Twitter Bootstrap Collapse to show some portion of the text and then the rest如何使用 Twitter Bootstrap Collapse 显示部分文本,然后显示其余部分
【发布时间】:2013-09-26 11:16:34
【问题描述】:

我有从数据库中显示的文本。我想在页面加载时显示一部分文本(最多某个字符数),然后使用 Twitter Bootstrap 的“折叠”功能显示其余文本。我不确定如何做到这一点。这是我目前所拥有的:

<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseOne">See More...</a>
<div id="collapseOne" class="accordion-body collapse"><span class="description_text">{{$artist->description}}</span></div>

点击“查看更多”链接时,这将显示“描述”字段中包含的整个文本。我想要的是在页面加载时显示的部分文本,然后在单击查看更多按钮时显示(并切换)其余部分。当显示全文时,将“查看更多”按钮更改为“查看更少”也会很好。

【问题讨论】:

    标签: twitter-bootstrap laravel laravel-4 collapse


    【解决方案1】:

    你可以在刀片标签内运行 PHP,所以;

    <a class="accordion-toggle" data-toggle="collapse" 
        data-parent="#accordion2" href="#collapseOne">
        {{ substr($artist->description,0,30).'...' }}
    </a> 
    

    最后的 substr 参数是要包含的字符数

    要更改链接文本,您需要编写一些 jquery 来捕获 show.bs.collapse 回调并替换链接的 innerhtml。

    此Twitter bootstrap 3.0 icon change on collapse 类似,但正在更改图标。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-14
      • 1970-01-01
      相关资源
      最近更新 更多