Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery ui 解除绑定小部件事件_Jquery Ui_Jquery - Fatal编程技术网

Jquery ui 解除绑定小部件事件

Jquery ui 解除绑定小部件事件,jquery-ui,jquery,Jquery Ui,Jquery,我正在编写我自己的小部件,除了destroy方法外,所有的工作都很好。似乎所有事件都没有正确解开 (function($) { var _super = $.Widget.prototype; // $.widget("my.cool", { _create: function() { var $self = this, $element = this.widget(); $element.mousedow

我正在编写我自己的小部件,除了destroy方法外,所有的工作都很好。似乎所有事件都没有正确解开

(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");
        }
    });
}) (jQuery);
要测试它,请执行以下操作:

$("<div>").cool().cool("destroy").trigger("mousedown").data("events")
$(“”).cool().cool(“销毁”).trigger(“mousedown”).data(“事件”)
即使已销毁,我也会显示警报(“已选择”),事件不会正确解除绑定,我可以在事件数据中看到“mousedown”

这有什么问题吗?

Doh

我发现为什么,事件应该这样绑定:

$element.bind("mousedown.cool", $self.select);
$element.mousedown($self.select);
不是这样的:

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