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

我正在使用jquery-plugin qTip。 在我的页面中销毁所有工具提示的命令是什么?

我试过了:

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

但它没有用……谢谢

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

qTip2是这个脚本的新版本,但我想指出一件事。

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

这段代码没有破坏所有的工具提示 – 它只是删除了他们的容器。 附加到调用工具提示的对象的所有处理程序和事件仍然可以在浏览器的内存中使用。

在qTip中删除工具提示及其处理程序,你必须使用:

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

要么

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

在qTip2中使用此:

 $(mytooltip).remove(); 

会自动调出api并彻底销毁工具提示和它的处理程序。

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

qtip("destroy")是buggy(版本2.1.1)并没有清除所有内容。

我发现这是一个正确的解决方法:

 // 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"); } 

看起来越野车。 我对此有一些好运,但它没有恢复原来的标题。 我怀疑destroy不会那样做……

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

看来你不能在没有qTip的情况下调用元素上的destroy – 它不会以静默方式失败,但抛出exception并停止循环。

我经历过api-call

 $(selector).qtip('destroy') 

并不能可靠地删除所有qtip数据,尤其是在同时使用多个qtips时。

在我的情况下,我不得不删除一个可见的 qtip并成功使用此解决方法:

 $(selector).removeData('qtip'); $('.qtip :visible').remove(); 
  if ( jQuery( '.qtip' ).length > 0 ) { jQuery( "#IdElement").qtip("destroy"); } 

这些答案都没有帮助我。

就我而言,我在一个带有关闭按钮的元素上有一个qtip。 关闭按钮删除了元素,因此在删除元素后没有参考点来删除qtip。

我认为$('.qtip:visible').remove()可以工作,但它以某种方式删除了页面上的所有qtips,而不是我想删除的单个qtips。

我注意到可见的qtip被赋予了qtip-active类,所以对我qtip-active是:

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

可能有点晚了,但是当ajax调用替换页面中的内容,删除目标qtip2对象然后销毁它们时,我遇到内存和页面加载问题,所以即使目标已经消失,一些元素仍然存在。

基于有时你想要清理所有qtips2元素和数据的事实,无论原始对象是否存在,一些工具提示元素都保留在主体上,所以当原始目标消失时,没有简单的方法来调用destroy () 方法。

除非你这样做,否则搜索创建的对象而不是目标。

 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. }); 

我使用JQuery来解决冲突问题,但你可以使用“$”(符号)而不是JQuery

关于什么:

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

似乎正在使用qTip2 3.0.2版。