[英]Add a checkbox inside Bootstrap 5 tabs
I intend to put a checkbox inside Bootstrap 5 tabs.我打算在 Bootstrap 5 选项卡中放置一个复选框。 The problem is that the checkbox is not selectable.
问题是该复选框不可选择。 If you enable the alert line on js panel, you will see the tabs script toggle the checkbox and won't let it be toggled.
如果您在 js 面板上启用警报行,您将看到 tabs 脚本切换复选框并且不会让它被切换。
I could make it work by using button
tag instead of a
, yet this can not be an option as the HTML code is rendered by a driver over which I don't have any control.我可以通过使用
button
标签而不是a
来使其工作,但这不是一个选项,因为 HTML 代码是由我无法控制的驱动程序呈现的。 I need to make it work by js or CSS.我需要通过 js 或 CSS 使其工作。
Can anyone help?任何人都可以帮忙吗?
const cbTab2 = document.getElementById("cb-tab-2"); cbTab2.addEventListener( "click", function (e) { // capture checkbox click // alert("captured"); console.log("captured"); } );
<:-- CSS only --> <link href="https.//cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min:css" rel="stylesheet" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous"> <.-- JavaScript Bundle with Popper --> <script src="https.//cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-A3rJD856KowSb7dwlZdYEkO39Gagi7vIsF0jrRAoQmDKKtQBHUuLZ9AsSv4jD4Xa" crossorigin="anonymous"></script> <ul class="nav nav-pills" id="pills-tab" role="tablist"> <li class="nav-item"> <a class="nav-link active" id="tab-1" data-bs-toggle="pill" data-bs-target="#tab-1-content" type="button" role="tab">Tab 1</a> </li> <li class="nav-item" role="presentation"> <a class="nav-link" id="tab-2" data-bs-toggle="pill" data-bs-target="#tab-2-content" type="button" role="tab"> <input type="checkbox" id="cb-tab-2" name="cb-tab-2"> Tab 2 </a> </li> </ul> <div class="tab-content" id="pills-tabContent"> <div class="tab-pane active" id="tab-1-content" role="tabpanel">Tab 1 Content</div> <div class="tab-pane" id="tab-2-content" role="tabpanel">Tab 2 Content</div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.