我目前可以在悬停时使用可访问的工具提示。 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');
});
最佳答案
添加"trigger" option到你的原始代码:
$(function () {
$('[data-toggle="tooltip"]').tooltip({ trigger: 'click' });
});
<小时/>
在第二个 fiddle 中,您不再在按钮元素上调用 .tooltip()
。您必须调用该函数来检测工具提示。默认情况下,将鼠标悬停在按钮上会触发工具提示。您可以通过为 .tooltip()
的调用提供 options
对象来更改它。具体来说,您可以包含“触发”选项。
关于javascript - 单击按钮时显示工具提示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37903542/