javascript - Twitter Bootstrap 使用 "Collapse"插件扩展文本

标签 javascript jquery twitter-bootstrap

有没有人知道如何使用twitter bootstrap collapse plugin显示了一些文本(比如 100 个字符),然后单击按钮展开文本以显示其余部分?

Here's a JSFiddle that demonstrates the following issues I'm having :

  1. 隐藏文本显示在 行中。如果句子不会在视觉上被打乱,那将是更可取的。
  2. icon-plus-sign 指示器的显示未切换(不会在显示隐藏文本时消失并重新出现,反之亦然)。

完全可用的 HTML:

<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.0/css/bootstrap-combined.min.css" rel="stylesheet">
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.0/js/bootstrap.min.js"></script>

<div class="" data-toggle="collapse" data-target="#div1" >
     <span><b>Div1:</b> This is a sentence at the end of the first 100 characters that gets truncated </span>
 <i class='icon-plus-sign'></i> 
</div>
<div id="div1" class="collapse" >such that characters 101 to infinity are not shown inline with the beginning of the sentence (<b>Div1</b>).</div>

<div class="" data-toggle="collapse" data-target="#div2" >
 <span><b>Div2:</b>This is a sentence at the end of the first 100 characters that gets truncated </span>
 <i class='icon-plus-sign'></i> 
</div>
<div id="div2" class="collapse" >such that characters 101 to infinity are not shown inline with the beginning of the sentence (<b>Div2</b>).</div>

最佳答案

我通过添加以下 JavaScript 让它工作:

$("div").on("hide", function() {
    $(this).prev("div").find("i").attr("class","icon-plus-sign");
    $(this).css("display","");
    $(this).css("height","5px");
});
$("div").on("show", function() {
    $(this).prev("div").find("i").attr("class","icon-minus-sign");
    $(this).css("display","inline");
    $(this).css("height","5px");
});

以及以下 CSS:

div[data-toggle="collapse"] {
    float: left;
}

Example fiddle is here .

旁注

我个人不会为此使用 Bootstrap 折叠插件。我会使用像 JQuery Expander 这样的专用插件结合 Bootstrap 图标。

一个不同的example fiddle is here .

关于javascript - Twitter Bootstrap 使用 "Collapse"插件扩展文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14940166/

相关文章:

javascript - 向 Accordion 添加关闭按钮

javascript - .split(/\s+/) 和 .split ("") 之间的区别?

javascript - Firefox 中的 Event.target 问题

css - 添加响应类后 YouTube 视频不显示

html - 3 列网格导航栏 Bootstrap

javascript - JQuery:隐藏/显示非事件选项卡中的元素

javascript - Highcharts:如何将数据从 JSON 加载到 xAxis.categories 和 series.data?

javascript - NodeJS Http 发布 JSON 数据

javascript - 如何比较没有年份的两个日期?只有月和日

javascript - summernote 在 img 中添加类