javascript - 单击按钮时显示工具提示

标签 javascript jquery

我目前可以在悬停时使用可访问的工具提示。 https://jsfiddle.net/lakenney/c1rogqxw/

<!-- Alert -->
<button class="btn btn-xs btn-info gly-radius" data-toggle="tooltip" data-placement="bottom" data-original-title="Click any question mark icon to get help and tips with specific tasks" aria-describedby="tooltip">
  <span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span>
  <span class="sr-only">Click any question mark icon to get help and tips with specific tasks</span>
 <!-- Alert -->
</button>

现在我想让它在 Click 上运行。我遵循 Julien Vernet 的示例,只是添加了辅助功能标记。 https://themeavenue.net/show-hide-element-onclick-using-boostrap-jquery/ ...哦,我使用按钮而不是 href

这是我到目前为止所拥有的:

<button class="btn btn-xs btn-info gly-radius" data-toggle="tooltip" data-placement="bottom" data-original-title="Click any question mark icon to get help and tips with specific tasks" aria-describedby="tooltip">
  <span class="glyphicon glyphicon-question-sign" aria-hidden="true"></span>
  <span class="sr-only">Click any question mark icon to get help and tips with specific tasks</span>
  <!-- Alert -->
</button>

$('[data-toggle="tooltip"]').click(function (event) {
       event.preventDefault();
       var target = $(this).attr('href');
       $(target).toggleClass('hidden show');
});

https://jsfiddle.net/lakenney/c1rogqxw/4/

最佳答案

添加"trigger" option到你的原始代码:

$(function () {
  $('[data-toggle="tooltip"]').tooltip({ trigger: 'click' });
});

jsfiddle

<小时/>

在第二个 fiddle 中,您不再在按钮元素上调用 .tooltip() 。您必须调用该函数来检测工具提示。默认情况下,将鼠标悬停在按钮上会触发工具提示。您可以通过为 .tooltip() 的调用提供 options 对象来更改它。具体来说,您可以包含“触发”选项。

关于javascript - 单击按钮时显示工具提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37903542/

相关文章:

javascript - Jasny Bootstrap Off Canvas 'Reveal' 方法 - 故障排除

javascript - 如何使用javascript或jquery获取td值的字体颜色或文本颜色

javascript - 使用 jquery 检查 div 中的所有值是否唯一

javascript - Onclick JavaScript 在 IE 中无法正常工作

javascript - 由于未捕获类型错误 : Cannot set property 'onclick' of null,无法关闭 Modal

jquery tablesorter 过滤器插件

java - 响应来自 Java 套接字的 AJAX 请求

javascript - 在 for 循环中将信息传递给模态

使用 jQuery 的 JavaScript 意外对象行为

嵌入在 Drupal 页面中的 jQuery 代码已覆盖其 css