开发者

Unbind widget events

I'm writing my own widget and all works fine except the destroy method. It seems that all events aren't unbind properly...

(function($) {
    var _super = $.Widget.prototype;

    //
    $.widget("my.cool", {
        _create: function() {
            var $self = this, $element = this.widget();
            $element.mousedown($self.select);
            _super._create.apply(this, arguments);
        },
        // Destroying widget
        destroy: function() {
            var $element = this.widget();
            $element.unbind(".cool");
            _super.destroy.apply(this, arguments);
        },
        select: function() {
            alert("selected");
        }
    });
}) (j开发者_Go百科Query);

To test it :

$("<div>").cool().cool("destroy").trigger("mousedown").data("events")

Even destroyed, I show the alert("selected"), events aren't unbind properly and I can see the "mousedown" in events data.

What's wrong with this?


Doh !

I found why, event should be bind like this :

$element.bind("mousedown.cool", $self.select);

And not like this :

$element.mousedown($self.select);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜