简体   繁体   English

qTip(jQuery插件)如何删除页面中的所有qtips?

[英]qTip (jQuery plug-in) how can I remove all qtips in my page?

I'm using the jquery-plugin qTip. 我正在使用jquery-plugin qTip。 What's the command to destroy all tooltips in my page ? 在我的页面中销毁所有工具提示的命令是什么?

I tried: 我试过了:

$('.option img[title], span.taxonomy-image-link-alter img[title]').qtip("destroy");

But it didn't work... Thanks 但它没有用......谢谢

我用$(".qtip").remove();解决了$(".qtip").remove();

qTip2 is newer version of this script, but I would just like to point out 1 thing. qTip2是这个脚本的新版本,但我想指出一件事。

$(".qtip").remove();

This piece of code didn't destroy all the tooltips - it simply removed their containers. 这段代码没有破坏所有的工具提示 - 它只是删除了他们的容器。 All the handlers and events attached to objects which invoked the tooltips are still avaiable in browser's memory. 附加到调用工具提示的对象的所有处理程序和事件仍然可以在浏览器的内存中使用。

In qTip to delete the tooltip and it's handler scompletely you would have to use: 在qTip中删除工具提示和它的处理程序scompletely你必须使用:

$(mytooltip).qtip("destroy");

or 要么

$(mytooltip).qtip('api').destroy(); 

In qTip2 however using this: 在qTip2中使用此:

$(mytooltip).remove();

Would automaticaly call out the api and destroy tooltip and it's handlers completely. 会自动调出api并彻底销毁工具提示和它的处理程序。

$('.qtip').each(function(){
  $(this).data('qtip').destroy();
})

qtip("destroy") is buggy (version 2.1.1) and doesn't clear everything. qtip("destroy")是buggy(版本2.1.1)并没有清除所有内容。

I found this as a proper workaround: 我发现这是一个正确的解决方法:

// don't call destroy if not needed
if (element.data("qtip")) {
    // the 'true' makes the difference
    element.qtip("destroy",true);
    // extra cleanup
    element.removeData("hasqtip");
    element.removeAttr("data-hasqtip");
}

I experienced that the api-call 我经历过api-call

$(selector).qtip('destroy')

doesn't remove all qtip-data dependably, especially when using several qtips simultaneously. 不会可靠地删除所有qtip数据,尤其是在同时使用多个qtips时。

In my case I had to remove a visible qtip and successfully used this workaround: 在我的情况下,我不得不删除一个可见的 qtip并成功使用此解决方法:

$(selector).removeData('qtip');
$('.qtip :visible').remove();

Looks buggy. 看起来越野车。 I've had some luck with this, but it does not restore the original titles. 我对此有一些好运,但它并没有恢复原来的标题。 I suspect destroy doesn't do that either... 我怀疑destroy不会那样做......

$('span.taxonomy-image-link-alter img')
    .filter(function(){return $(this).data('qtip');})
    .qtip('destroy');

It seems you cannot call destroy on elements without qTip - it doesn't fail silently, but throws an exception and stops the loop. 看来你不能叫destroy的元素,而qTip -它不默默地消失,而是抛出一个异常,并停止循环。

   if ( jQuery( '.qtip' ).length > 0 )
    {
        jQuery( "#IdElement").qtip("destroy");
    }

None of these answers helped me. 这些答案都没有帮助我。

In my case, I had a qtip on an element with a close button. 就我而言,我在一个带有关闭按钮的元素上有一个qtip。 The close button removed the element, so there was no reference point to remove the qtip after the element was removed. 关闭按钮删除了元素,因此在删除元素后没有参考点来删除qtip。

I thought $('.qtip:visible').remove() would work, but it somehow removed all of the qtips on the page, and not the single one that I wanted removed. 我认为$('.qtip:visible').remove()可以工作,但它以某种方式删除了页面上的所有qtips,而不是我想删除的单个qtips。

I noticed that the visible qtip is given a class qtip-active , so what worked for me was: 我注意到可见的qtip被赋予了一个qtip-active类,所以对我qtip-active是:

$('.qtip-active').remove();

It may be a little late, but I had issues with memory and page load when an ajax call replace the content in the page, deleting the target qtip2 objects before destroy them, so some elements remains even if the target had gone. 可能有点晚了,但是当ajax调用替换页面中的内容,删除目标qtip2对象然后销毁它们时,我遇到内存和页面加载问题,所以即使目标已经消失,一些元素仍然存在。

Based on the fact that sometimes you want to clean all qtips2 elements and data, no matter if the original object exist or not, some tooltip elements remains on the body, so when the original target has gone there is no easy way to call the destroy() method. 基于有时你想要清理所有qtips2元素和数据的事实,无论原始对象是否存在,一些工具提示元素都保留在主体上,所以当原始目标消失时,没有简单的方法来调用destroy () 方法。

Unless you do it searching for the created objects instead of the targets. 除非你这样做,否则搜索创建的对象而不是目标。

jQuery('div[id^="qtip-"]').each(function(){ //search for remaining objects

    _qtip2 = jQuery(this).data("qtip"); //access the data where destroy() exist.

    //if it's a proper qtip2 object then call the destroy method.
    if(_qtip2 != undefined){ 
        // the "true" is for immediate destroy
        _qtip2.destroy(true);
    }
    //if everything went right the data and the remaining objects in the body must be gone.
});

I used JQuery for a no conflict issue, but you can use "$" (symbol) instead of JQuery 我使用JQuery来解决冲突问题,但你可以使用“$”(符号)而不是JQuery

What about: 关于什么:

$('[data-hasqtip]').qtip('destroy', true);

Seems to be working with qTip2 version 3.0.2 . 似乎正在使用qTip2 3.0.2版。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM