【发布时间】:2020-05-17 05:40:47
【问题描述】:
我正在使用 Bootstrap Tables,目前正在使用他们提供的 Hoverable Rows。我使用了https://getbootstrap.com/docs/4.4/content/tables/#hoverable-rows 中的表格代码,并对其稍作修改以与 JS 一起使用。
<table class="table table-hover" id="myTable">
<thead>
<tr class="clickable-row">
<th scope="col">#</th>
<th scope="col">First</th>
<th scope="col">Last</th>
<th scope="col">Handle</th>
</tr>
</thead>
<tbody>
<tr class="clickable-row">
<th scope="row">1</th>
<td>Mark</td>
<td>Otto</td>
<td>@mdo</td>
</tr>
<tr class="clickable-row">
<th scope="row">2</th>
<td>Jacob</td>
<td>Thornton</td>
<td>@fat</td>
</tr>
<tr class="clickable-row">
<th scope="row">3</th>
<td colspan="2">Larry the Bird</td>
<td>@twitter</td>
</tr>
</tbody>
</table>
基本上我希望能够点击一行并保持悬停效果。然后当我再次单击它时,它将删除悬停。但我希望能够选择多行。
我找到了一些 JS,并且能够让它在只选择一行的情况下工作..
$('#myTable').on('click', '.clickable-row', function(event) {
$(this).addClass('active').siblings().removeClass('active');
});
我不太了解 JS,正在寻找一种方法来允许选择/取消选择多行。
我能够将 JS 更改为:
$('#myTable').on('click', '.clickable-row', function(event) {
$(this).addClass('active');
});
它允许我选择多个。但我无法取消选择它们。
【问题讨论】:
标签: javascript html css bootstrap-4