1

我正在使用线索提示 jQuery 插件。

我正在尝试添加我自己的关闭按钮。我试图调用的 jquery 是:

 $(document).bind('hideCluetip', function(e) {
  cluetipClose();
});

通过代码和 jquery 插入的按钮有很多对线索提示关闭()的引用,它使用它并且可以正常工作,因此据我所知,该功能可以正常工作。

我正在尝试使用

$('a.close-cluetip').trigger('hideCluetip');

我创建了我的链接:

<a href="#" class="close-cluetip">Close</a>

但它什么也没做。

我叫错了吗?

4

1 回答 1

1

The problem here is that in the cluetip plugin, the function clueTipClose() is inside a closure, so you have no access to it unless you're inside the closure (i.e. inside the plugin's code). Now I've gotta admit, this plugin doesn't seem to be set up to be all that extensible. If they made this function accessible via a "clueTip" object that was set up for each element that uses it, you'd be able to add another jQuery method to the end of the closure like this:

$.fn.cluetipClose = function() {
    return this.each(function() {
        var thisCluetip = findCluetipObj(this);

        if (thisCluetip)
            thisCluetip.cluetipClose();
    });
};

But you have the unfortunate luck of not being able to do this easily. It looks like this guy wrote his jQuery plugin with non-OO code inside of a closure. Poor you.

Now on the plus side, it seems this plugin is already running this code directly after it instantiates the cluetipClose() function. Have you tried just doing this from your code:

$('a.close-cluetip').trigger('hideCluetip');

Without redeclaring the document hideCluetip bind? I think that should probably work.

于 2011-02-09T17:29:39.923 回答