gpt4 book ai didi

html - 单击表格行中的按钮时 Bootstrap 折叠表格行

转载 作者:太空宇宙 更新时间:2023-11-04 06:23:46 25 4
gpt4 key购买 nike

在我的代码片段中,您可以看到一个只有一行的简单表格。在该行中,您可以看到一个按钮组。现在,如果您单击“主”按钮(重置按钮),您可以看到您单击的行下方的表格行将显示出来。这应该仅在您单击表格行时发生,而不是在您单击表格行内的按钮时发生。

另外,为什么恢复崩溃需要这么长时间?

<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
</head>

<body>
<div class="container body-content">
<table class="table m-0">
<thead class="thead-light">
<tr>
<th>
<span class="d-inline-block align-middle">table head</span>
<button type="button" class="btn btn-secondary btn-sm float-right">button text</button>
</th>
</tr>
</thead>
<tbody>
<tr data-toggle="collapse" href="#collapse2" role="button" aria-expanded="false" aria-controls="collapse2">
<td>
table content
<div class="btn-group float-right align-top" onclick=";">
<button type="button" class="btn btn-warning" onclick="alert('reset!');">reset</button>
<button type="button" class="btn btn-danger dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="sr-only">Toggle Dropdown</span>
</button>
<div class="dropdown-menu bg-danger">
<a class="dropdown-item bg-danger text-white" onclick="alert('delete!');">delete</a>
</div>
</div>
</td>
</tr>
<tr class="collapse" id="collapse2">
<td>
<div class="progress mb-2" data-toggle="tooltip" data-placement="top" title="progress text 1">
<div class="progress-bar" role="progressbar" style="width: 0%; background-color: #1AFF00" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">progress text 1</div>
</div>
<div class="progress mb-2" data-toggle="tooltip" data-placement="top" title="progress text 2">
<div class="progress-bar" role="progressbar" style="width: 0%; background-color: #2B00FF" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">progress text 2</div>
</div>
</td>
</tr>
</tbody>
</table>
<script>
$(window).on('load', function () {
$('[data-toggle="tooltip"]').tooltip();
});
</script>
</div>
</body>

</html>

最佳答案

回答原始问题以及评论中的问题。

  1. 当您单击按钮时,事件会冒泡并在行元素上触发,这就是行的单击处理程序(切换部分)也起作用的原因。为防止出现这种情况,您可以通过在重置按钮的点击处理程序中调用 event.stopPropagation() 来阻止点击事件冒泡。

  2. decollapse 很慢,因为默认情况下 Bootstrap 在切换过程中应用类 .collapsing。这允许应用一些动画。似乎默认情况下它只是动画元素的高度。但是,在您的情况下,动画不起作用,因为表格行的高度不能小于内容高度,但是预期动画的延迟仍然存在。您可以像我在下面所做的那样,通过用 none 覆盖默认的 transition禁用动画,或者只使用表格以外的其他东西,例如div.

根据我的意见,这是您的代码的更新版本:

.collapsing {
-webkit-transition: none !important;
transition: none !important;
display: none;
}
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" />
</head>

<body>
<div class="container body-content">
<table class="table m-0">
<thead class="thead-light">
<tr>
<th>
<span class="d-inline-block align-middle">table head</span>
<button type="button" class="btn btn-secondary btn-sm float-right">button text</button>
</th>
</tr>
</thead>
<tbody>
<tr data-toggle="collapse" href="#collapse2" role="button" aria-expanded="false" aria-controls="collapse2">
<td>
table content
<div class="btn-group float-right align-top" onclick=";">
<button type="button" class="btn btn-warning" onclick="alert('reset!');event.stopPropagation();">reset</button>
<button type="button" class="btn btn-danger dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="sr-only">Toggle Dropdown</span>
</button>
<div class="dropdown-menu bg-danger">
<a class="dropdown-item bg-danger text-white" onclick="alert('delete!');">delete</a>
</div>
</div>
</td>
</tr>
<tr class="collapse" id="collapse2">
<td>
<div class="progress mb-2" data-toggle="tooltip" data-placement="top" title="progress text 1">
<div class="progress-bar" role="progressbar" style="width: 0%; background-color: #1AFF00" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">progress text 1</div>
</div>
<div class="progress mb-2" data-toggle="tooltip" data-placement="top" title="progress text 2">
<div class="progress-bar" role="progressbar" style="width: 0%; background-color: #2B00FF" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">progress text 2</div>
</div>
</td>
</tr>
</tbody>
</table>
<script>
$(window).on('load', function () {
$('[data-toggle="tooltip"]').tooltip();
});
</script>
</div>
</body>

</html>

关于html - 单击表格行中的按钮时 Bootstrap 折叠表格行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55260266/

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