如何在jquery工具提示中放置关闭按钮

时间:2014-07-08 12:27:58

标签: jquery css jquery-tooltip

我在我的网页上使用了this tooltip。现在,我想在工具提示中添加一个“关闭按钮”,因此如果用户点击该按钮,工具提示将被关闭(虽然该工具提示会在一段时间后自动关闭,但我也需要添加关闭按钮功能)。这是我的工具提示:

当用户点击关闭按钮时,我需要关闭工具提示

我将测试代码放在jsfiddle

所以,基本上我希望,我的代码应该是这样的:

$('.tooltipster-content').on('click', '.close', function() {
    $('tooltipster-base').hide();
});

但是,此代码无法在我的网页上运行。

4 个答案:

答案 0 :(得分:2)

它不起作用的原因是因为当您绑定事件时,您在小提琴中委托的事件不会出现在页面上。请尝试以下方法:

$(document).on('click', '.close', function() {
    $('.tooltipster-base').hide();
});

此外,您在绑定的.回调中错过了$('.tooltipster-base') jQuery选择器前面的click

<强> DEMO

答案 1 :(得分:2)

我认为它会更加正确:

$(document).on('click', '.close', function() {
    $('.tooltip').tooltipster('hide');
});

DEMO

答案 2 :(得分:0)

试试这个

$(".close").click(function(){
$(this).parent().hide();
});

最好编辑tooltipster.min.js

在tooltipster.min.js中找到m.showTooltip();

在tooltipster.min.js

中的m.showTooltip();下添加以下行
$(".close").parent().parent().show();                               
$(".close").click(function(){$(this).parent().parent().hide();});

Fiddle

答案 3 :(得分:0)

以下是tooltipster^4.0的最新解决方案:

functionReady: function (instance, helper) {
    $(instance._$tooltip).on('click', '.close-btn', function () {
        instance.close();
    });
}