jQuery工具提示,但单击而不是悬停

问题描述:

我们使用标题属性在鼠标悬停时显示某些内容。现在,我们希望它在单击时显示。如何获得一个看起来像标题/工具提示的浮动框,但是可以按需显示和隐藏而不是与悬停绑定?

We were using 'title' attributes to display something on mouseover. We want it now to display on a click. How can I get a floating box that looks like a title/tooltip, but can be shown and hidden on demand instead of being tied to a hover?

如果您想对其进行手动编码,则应该可以完成此工作:

If you feel like handcoding it, this should do the job:

html:

<div id="tooltip" style="display:none;">bla bla</div>

<div id="yourLink">Click here to show the tooltip!</div>

和JS:

$('#yourLink').click(function(){
  $('#tooltip').toggle();
});

您只需要正确设置工具提示div的样式

You just need to style correctly the tooltip div

那里也有不错的工具提示插件。 iftrue提到了一个,还有这一个

There are also nice tooltip plugins out there. iftrue mentioned one, there is also this one