2017-10-13 96 views
0

我有一张按发票对行项目进行排序的表,并且使用引导程序折叠来显示/隐藏发票。整个发票行用作表格的切换。如何在引导手风琴切换中使用链接

/-----------------------------------------------------\ 
| #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>和链接周围的ID在第一<th>

这是显示当前功能的JSFiddle

有没有什么办法让链接工作而无需将其从行中删除或使行不再切换崩溃?

+1

也许这样会有帮助吗? https://stackoverflow.com/questions/13682435/preventing-child-from-firing-parents-click-event –

+0

它确实。谢谢! – amflare

回答

0

使用JavaScript或jQuery的重定向

<script> 
    $('#accordion a').click(function(){ 
    window.location = $(this).attr('href'); 
    return false; 
    }); 
</script> 
0

我的问题的解决方案被发现here

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

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