jQuery:如何删除醉意的工具提示?

时间:2010-08-10 13:16:24

标签: jquery tooltip

我使用.placeTaken类将divy工具提示添加到div。然后用户可以拖动框,所以我删除了类并将其添加到新的div中。当发生这种情况时,我向该div添加一个新的醉意工具提示,并且工作正常,但我想删除旧的。

他们说如果您希望通过将title属性设置为空字符串来删除工具提示,请改为设置原始标题属性。我试过$("#"+dropFromId).attr("original-title", "");,但工具提示仍在那里。我甚至无法通过设置另一个原始标题来更改工具提示标题。

我做错了什么?

编辑:我想我没有给你们足够的信息。我使用ajax来获取从数据库中获取的位置。 PHP返回一个关联数组(客户),然后我在我的JavaScript中使用,其中所发生的匹配名称。删除时所采取的位置会发生变化,因此我再次执行ajax函数以使用所有拍摄的位置更新数组。首先,我向所有采取的地方添加了醉意的工具提示,如此

$("#map div.placeTaken").tipsy({gravity: 'w', html: true, fade: true, title:
    function(){
        // id could for example be map74, substring to 74
        var id = $(this).attr("id").substring(3,6);
        return '<div>'+customers[id]+'</div><br />';
    }
});

因此标题等于数组中匹配的位置。我希望我能够解释这个问题。当盒子放在一个新的地方时,就会发生这种情况

$("#map div span").bind( "dragstop", function(event, ui) {
        // some code here to change the .placeTaken class       
        // update database with the new place
        $.ajax({
            type: "POST",
            url: "map.php",
            data: "dropFromId="+ dropFromId.substring(3,6) +"& dropToId="+ dropToId.substring(3,6),
            success: function(){
            // ajax function to update the js array with new places
            customerTooltip(); 
            }
        });

        // on this place, add tooltip
        $("#"+dropToId).tipsy({gravity: 'w', html: true, fade: true, title:
            // funktion för att avgöra vilken title som ska användas
            function(){
                var id = dropToId.substring(3,6);
                return '<div>'+customers[id]+'</div><br />';
            }
        });
    }   
});

这一切都运行正常,所以我认为我只需将DropFromId标题更改为“”,以便删除它。

8 个答案:

答案 0 :(得分:26)

使用$(".tipsy").remove();似乎可以解决问题,因为当显示工具提示时,带有tipsy类的div会附加到文档正文中。

请确保您不在其他地方使用tipsy课程(例如,将您的工具提示称为toolTip

答案 1 :(得分:11)

删除tipsy的最简单方法;

$('.tipsy:last').remove();

答案 2 :(得分:2)

$("#"+dropFromId)[0].setAttribute('original-title', '')

答案 3 :(得分:1)

$("#tipsyfiedElement").unbind('mouseenter mouseleave'); // Or whatever event trigger the tiptool

答案 4 :(得分:1)

使用方式更简单:

$('body').find('.tipsy').each(function(){
    $(this).remove();
});

答案 5 :(得分:0)

我最近遇到过这个问题,我的解决方法如下:

使用此选项将original-title属性设置为“stop”:

$('.myElement').attr('original-title','stop');

然后,在 jquery.tipsy.js 中,将代码更改为以下内容:

...
} else if (typeof opts.title == 'function') {
    title = opts.title.call(this);
}

if (title != 'stop') {    //line 32
    ...
    ...
}                         //line 62
...

在我的版本(0.1.7)中,添加的代码从第32行开始,在第62行结束括号.Thisy应该看到你的title属性等于'stop'而不会尝试打开工具提示。

此外,这会向控制台吐出一些错误。它没有任何区别,但是如果你想摆脱它,在第73行添加它(在添加前面的代码之后)

try { tip.remove(); } catch(err){}

POW

答案 6 :(得分:0)

使用:.unbind('mouseenter mouseleave'); 删除一个醉意的方法。

答案 7 :(得分:0)

由于触控/点击事件的复杂性,特别是在iPad上,谷歌搜索了一个在移动设备上禁用Tipsy的情况后我看到了这个问题。

我决定实施的解决方案是在jquery.tipsy.js文件的顶部添加一个小测试。

禁用触摸(移动)设备上的Tipsy:     var deviceAgent = navigator.userAgent.toLowerCase();

var isTouchDevice = Modernizr.touch ||
(deviceAgent.match(/(iphone|ipod|ipad)/) ||
deviceAgent.match(/(android)/) ||
deviceAgent.match(/(iemobile)/) ||
deviceAgent.match(/iphone/i) ||
deviceAgent.match(/ipad/i) ||
deviceAgent.match(/ipod/i) ||
deviceAgent.match(/blackberry/i) ||
deviceAgent.match(/bada/i));

function Tipsy(element, options) {
    this.$element = $(element);
    this.options = options;
    this.enabled = !isTouchDevice;
    this.fixTitle();
};

See: The best way to detect if user agent supports touch

相关问题