如何使引导工具提示在纯 JS 中始终可见?
您好,我正在寻找有关使页面的工具提示始终可见的解决方案,并遇到了以下问题 所以问题。然而,为此提供的所有解决方案都是使用 JQuery。
这是用于始终显示工具提示的代码,我想将其转换为 JS,但我不知道如何转换。我还没有找到太多关于此的文档。
$('p a').tooltip({placement: 'bottom',trigger: 'manual'}).tooltip('show');
上面的 JQuery 代码似乎工作正常。您可以在此处 (w3schools) 进行测试。
这是我的 HTML:
<span class="span-navigator-above-1" data-toggle="tooltip" data-original-title="Tooltip on top" data-placement="top" style="z-index: 3;">
<div data-title="Event Information" id="progress-bar-indicator-button-1" class="progress-step progress-step-active"></div>
</span>
更新 1:
根据我对 coll 答案的评论
in a loop: {
//Indicator Progress Span (above bullet with text)
span = document.createElement("span");
span.className = "indicator-tooltip-target";
span.style.zIndex = "3";
span.setAttribute("data-toggle","tooltip");
span.setAttribute("data-original-title", "test");
}
later in the code in another loop: {
let tooltips_target = document.getElementsByClassName("indicator-tooltip-target");
for(var i=0; i<tooltips_target.length; i++){
let tooltip = new bootstrap.Tooltip(tooltips_target[i]);
tooltip.show();
}
}
Hi I was looking for solutions about having the tooltips of my page always visible and came accross the following SO question. However all the solutions provided to this is using JQuery.
Here is the code used to always show the tooltip which I want to convert to JS but I don't know how. I haven't found much documentation about this.
$('p a').tooltip({placement: 'bottom',trigger: 'manual'}).tooltip('show');
The JQuery code above seems to be working okay. You can test it here (w3schools).
And Here is my HTML:
<span class="span-navigator-above-1" data-toggle="tooltip" data-original-title="Tooltip on top" data-placement="top" style="z-index: 3;">
<div data-title="Event Information" id="progress-bar-indicator-button-1" class="progress-step progress-step-active"></div>
</span>
UPDATE 1:
As per my comment on coll's answer
in a loop: {
//Indicator Progress Span (above bullet with text)
span = document.createElement("span");
span.className = "indicator-tooltip-target";
span.style.zIndex = "3";
span.setAttribute("data-toggle","tooltip");
span.setAttribute("data-original-title", "test");
}
later in the code in another loop: {
let tooltips_target = document.getElementsByClassName("indicator-tooltip-target");
for(var i=0; i<tooltips_target.length; i++){
let tooltip = new bootstrap.Tooltip(tooltips_target[i]);
tooltip.show();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尽管您已经更新了标签并且没有明确说明您的询问:
在 Bootstrap 4 的文档,工具提示需要 jquery 才能发挥作用:
在 Bootstrap 5 的文档中,您可以通过 vanilla JS 运行 show 命令: :
Though you've updated your tags and don't explicitly state which your asking about:
In Bootstrap 4's docs, jquery is required for tooltips to function:
In Bootstrap 5's docs, you can run the show command through vanilla JS with: