gpt4 book ai didi

javascript - 如何在 Bootstrap Accordion 切换中使用链接

转载 作者:行者123 更新时间:2023-11-28 02:49:34 25 4
gpt4 key购买 nike

我有一个按发票对行元素进行排序的表格,并且我正在使用 bootstrap collapse 按发票显示/隐藏。整个发票行充当表格的切换开关。

/-----------------------------------------------------\
| #547 | 2017-10-10 | $65.00 | Invoice | PAID |
|------|------------|--------|-----------------|------|
| | 2017-10-10 | $35.00 | seeded for test | |
| | 2017-10-10 | $15.00 | seeded for test | |
| | 2017-10-10 | $15.00 | seeded for test | |
|------|------------|--------|-----------------|------|
| #548 | 2017-10-13 | $46.00 | Invoice | OPEN |
|------|------------|--------|-----------------|------|
| | 2017-10-12 | $23.00 | Test form | |
| | 2017-10-12 | $23.00 | Test form | |
\-----------------------------------------------------/

当我尝试将 ID 号链接到详细信息页面时,问题就来了。它根本行不通。悬停工作正常,元素检查器确认链接存在,但单击它只会打开/关闭行元素。

<table class="table table-striped" id="accordion">
<?php foreach($invoices as $invoice): ?>
<thead class="accordion-table" data-toggle="collapse" data-parent="#accordion" href="#collapse<?=$invoice['id']?>" aria-expanded="true" aria-controls="collapse<?=$invoice['id']?>">
<tr>
<th><a href="/report/invoice/<?=$invoice['id']?>">#<?=$invoice['id']?></a></th>
<th><?=date('Y-m-d',strtotime($invoice['created']))?></th>
<th>$<?=number_format($invoice['amount'],2)?></th>
<th><?=$invoice['description']?></th>
<th><?=$invoice['invoiceStatus']?></th>
</tr>
</thead>
<tbody id="collapse<?=$invoice['id']?>" class="collapse accordion-body" role="tabpanel" >
<?php foreach($transactions[$invoice['id']] as $transaction): ?>
<tr>
<td></td>
<td><?=date('Y-m-d',strtotime($transaction['created']))?></td>
<td>$<?=number_format(abs($transaction['amount']),2)?></td>
<td><?=$transaction['description']?></td>
<td></td>
</tr>
<?php endforeach; ?>
</tbody>
<?php endforeach; ?>
</table>

开关位于 <thead> 中链接位于第一个 <th> 中的 id 周围.

这是一个JSFiddle显示当前功能。

有没有什么方法可以让链接正常工作,而无需将其从行中删除或使行不再切换折叠状态?

最佳答案

找到了我的问题的解决方案here .

我向 <a> 添加了一个事件监听器标记并使用 jQuery 的 stopPropagation() 防止 Bootstrap Collapse 接管的方法。

$("a.invoice-link").click(function(event){
event.stopPropagation();
});

关于javascript - 如何在 Bootstrap Accordion 切换中使用链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46734224/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com