【问题标题】:Show row collapsed in Bootstrap在 Bootstrap 中显示折叠的行
【发布时间】:2018-10-19 07:23:14
【问题描述】:
$i = 0;
while($row = $statement->fetch()) {
    $current_id = 'id-' . $i;
    $i++;
    echo "
        <tr>
            <td>
                <p>
                    <button class='btn btn-primary' 
                         type='button' 
                         data-toggle='collapse' 
                         data-target='#<?=$current_id?>' 
                         aria-expanded='false' 
                         aria-controls='Collapse'>
                        Button with data-target
                    </button>
                </p>
                <div class='collapse' id='<?=$current_id?>'>
                    <div class='card card-block'>
                        Here is the content for block which will be shown when the button. This uses button with data-target attribute for collapsing.
                    </div>
                </div>
            </td>
    ";
}

我的错误在哪里?它不会折叠,但我需要行的唯一 ID。

【问题讨论】:

  • 不确定它是否能解决您的问题。除非在复制到您的问题时出错,否则您的 while 循环缺少右括号 }
  • 这个} 是不是只有这个td 的一个片段,崩溃的地方是:) 但是我的代码中有这个} :) 这个错误只在我更改数据目标时出现像#ttt 和 id 到 ttt 一样正常,然后它会变形,但通过这个尝试我不会:)
  • bootstrap initially collapsed element 的可能重复项 - 我认为您需要 &lt;div class='accordian-body collapse' id...
  • 顺便说一句,我添加了一个结束 } 只是为了完整性。
  • class='accordian-body collapse' id... 不适合我。

标签: php mysql row


【解决方案1】:

现在它可以工作了。我现在要做的:

 $ccid = "#$current_id";
 $ccid2 = "$current_id"; 

然后我将变量放在 ID 和 Href 中,如下所示:

href='".$ccid."'
id='".$ccid2."'

解决了这个问题。谢谢大家!

【讨论】:

  • 为什么是第二个变量?你可以简单地使用href='#."$ccid."'
  • 甚至href='#."$current_id".'
猜你喜欢
  • 1970-01-01
  • 2018-11-05
  • 1970-01-01
  • 2017-06-05
  • 2015-02-17
  • 2019-02-07
  • 2020-12-12
  • 2013-11-10
  • 1970-01-01
相关资源
最近更新 更多