我仍在学习PHP和Javascript。我使用modal显示我的购物车项目,但如果显示的购物车项为空,我不知道如何禁用modal按钮。
<div class="modal fade bd-example-modal-lg" id="cartmodal" tabindex="-1" data-target=".bd-example-modal-lg" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Lihat Bahan Arkib</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<table class="table table-secondary" id="cart_table" style="width: 100%;">
<thead class="">
<tr class="">
<th>No.Rujukan & No.Penerimaan</th>
<th>Tajuk</th>
<th>Tindakan</th>
</tr>
</thead>
<tbody id='cartBody'>
<?php if (isset($_SESSION['cart'])) {
foreach($_SESSION['cart'] as $k => $v){ ?>
<tr id="view-cart">
<td><?php echo $v['id_arkib'] ?> </td>
<td><?php echo $v['tajuk']?> </td>
<td><button class="btn btn-danger mdi mdi-delete deleteitem" required>Padam</button></td>
</tr>
<?php }
}?>
</tbody>
</table>
</div>
<div class="modal-footer">
<a type="submit" class="btn btn-primary" id="btn-mohon-cart" name="mohonbtn" href="<?php echo ROOT_PATH; ?>pusat_sumber/penyelidik/permohonan_penyelidik.php">Mohon</a>
</div>
</div>
</div>
</div>
在javascript:中
<button type="button" class="close" data-dismiss="modal" aria-label="Close" disabled={cart.length > 0 ? false : true}>