简体   繁体   English

jQuery cluetip('destroy')不会破坏/删除cluetip?

[英]jQuery cluetip('destroy') does not destroy/remove cluetip?

I'm trying to make sense of how cluetip actually works. 我想弄清楚cluetip究竟是如何运作的。 I have a dummy DOM structure which I did some alerts on to check if the cluetip has been removed after the cluetip('destroy') was called on the anchor element. 我有一个虚拟DOM结构,我做了一些警告,以检查在锚元素上调用cluetip('destroy')后是否已删除cluetip。 However, the cluetip div still appears to be alive and well. 然而,cluetip div似乎还活着。 This really confuses me... 这真让我困惑......

Correct me if I'm wrong... AFAIK, cluetip has 1 instance in the webpage, and it exists in a hierarchy of tags, ie cluetip > cluetip-outer > cluetip-inner. 纠正我,如果我错了... AFAIK,cluetip在网页上有1个实例,它存在于标签的层次结构中,即cluetip> cluetip-outer> cluetip-inner。 It appends itself somewhere to the DOM structure when it is first appended to a html element (in my case, an anchor). 当它首次附加到html元素(在我的例子中是一个锚点)时,它会将自身附加到DOM结构的某个位置。

So the question: would calling cluetip('destroy') on the html element actually remove the cluetip, or would it remove/reset some sort of variable in the cluetip (and if so, which variable)? 所以问题是:在html元素上调用cluetip('destroy')实际上会删除cluetip,还是会删除/重置cluetip中的某种变量(如果是这样,哪个变量)? Or am I totally off the track here? 或者我完全不在这里?

Thanks. 谢谢。

It looks like all the destroy function does is remove the event trigger (lines 28-30) 看起来所有的destroy函数都是删除事件触发器(第28-30行)

if (js == 'destroy') {
  return this.unbind('.cluetip');
}

If you want to ensure the data in the cluetip is gone, then clear it yourself: 如果您想确保cluetip中的数据消失,请自行清除:

$('#cluetip-inner').empty();

Update: To answer your question about seeing if an element has anything bound to it, I'll refer you to something I found from James Padolsey's site : 更新:要回答关于查看元素是否有任何约束的问题,我将向您推荐我从James Padolsey网站上找到的内容

// List bound events:
console.dir( jQuery('#elem').data('events') );

// Log ALL handlers for ALL events:
jQuery.each($('#elem').data('events'), function(i, event){
    jQuery.each(event, function(i, handler){
        console.log( handler.toString() );
    });
});

*Note: the console is referring to the Firebug console. *注意: console指的是Firebug控制台。

Try the following: 请尝试以下方法:

$(this).cluetip('destroy'); 
$(this).remove(); 

The remove() function should also unbind the events. remove()函数也应取消绑定事件。

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

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