我正在使用tooltipster ,并有一个工具提示,显示何时单击菜单按钮(该位工作正常)。 不过,我在使用工具提示内的关闭按钮关闭工具提示时遇到问题。
我一定错过了一些非常简单的东西。
HTML
<span class="tooltip-email-share"> Stuff </span>
<!-- is triggered by this link -->
<ul>
<...>
<li><a class="menu-share"></a></li>
<...>
</ul>
工具提示的 HTML(以防万一)
<div class="tt-email-share">
<span class="tt-close"></span>
<h1>Title</h1>
<form>
</form>
</div>
JS
// initiates the tooltip - trigger set to custom & autoClose is false, so it wont close without pressing the close button.
$('.tooltip-email-share').tooltipster({
theme: 'tooltipster-html-shadow',
interactive: 'true',
autoClose: 'false',
position: 'bottom',
speed: '200',
trigger: 'custom',
content: $('HTML Stuff in here')
});
// Shows the tooltip (this bit works a charm)
$('.menu-share').click(function(){
$('.tooltip-email-share').tooltipster('show');
});
// *should* close the tooltip (doesn't work)
$('.tt-close').click(function(){
$('.tooltip-email-share').tooltipster('hide');
});
最佳答案
解决方案是(感谢一位同事帮助我解决这个问题):
关闭按钮在我定位的时间点并不存在。因此,我必须添加一个 functionReady 函数,以便在加载工具提示后运行单击脚本。
完美运作。
$('.tooltip-email-share').tooltipster({
theme: 'tooltipster-html-shadow',
interactive: 'true',
autoClose: 'false',
position: 'bottom',
speed: '200',
trigger: 'custom',
content: $('HTML stuff in here'),
// new function here
functionReady: function(){
$('.tt-close').click(function(){
$('.tooltip-email-share').tooltipster('hide');
});
}
});
关于jquery - 工具提示关闭按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25983192/