duanlu9816 2019-07-04 13:19
浏览 61
已采纳

Bootstrap手风琴扩展全部

I have created an accordion from my database table where each row is a new card, the first column is the heading by which it expands and the remaining columns are the content of the collapsible part.

This works perfectly as expected, but was wondering if there is a way to try get a button outside of this that will expand them all?

$i = '0';

$var = '<div id="accordion">';

$sql = "SELECT * FROM table";
$stmt = DB::run($sql);
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){

    $col1 = $row['col1'];
    $col2 = $row['col2'];
    $col3 = $row['col3'];
    $col4 = $row['col4'];

    $i++;

    $var .= '<div class="card">';

        $var .= '<div class="card-header" id="heading'.$i.'">';
            $var .= '<button class="btn btn-link" data-toggle="collapse" data-target="#collapse'.$i.'" aria-expanded="true" aria-controls="collapse'.$i.'">';
                $var .= $col1;
            $var .= '</button>';
        $var .= '</div>';

        $var .= '<div id="collapse'.$i.'" class="collapse" aria-labelledby="heading'.$i.'" data-parent="#accordion">';
            $var .= '<div class="card-body">';
                $var .= $col2;
                $var .= $col3;
                $var .= $col4;
            $var .= '</div>';
        $var .= '</div>';

    $var .= '</div>';
}

$var .= '</div>';
  • 写回答

1条回答 默认 最新

  • dongsuoying9059 2019-07-31 08:54
    关注

    This is what worked for me in the end:

    function expand_all(){
        $('.collapse').each(function(){
            $(this).addClass('show');
        });
        $('.accordion-btn').each(function(){
            $(this).attr('aria-expanded','true');
        });
    }
    function collapse_all(){
        $('.collapse').each(function(){
            $(this).removeClass('show');
        });
        $('.accordion-btn').each(function(){
            $(this).attr('aria-expanded','false');
        });
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀