如何制作.unclick = unbind(在jquery中'点击'?

时间:2021-02-20 19:44:02

I want a shortcut notation for unbind('click'. I want .unclick to be unbind('click'.

我想要一个unbind的快捷符号('click'。我希望.unclick解除绑定('click'。

2 个解决方案

#1


I think you want something like this:

我想你想要这样的东西:

$.fn['unclick'] = function(){
   return this.unbind('click');
};

Now the following two lines are equivalent:

现在以下两行是等价的:

$(...).unbind('click');
$(...).unclick();

For all events (list of events copied from the jQuery source):

对于所有事件(从jQuery源复制的事件列表):

var events = ('blur,focus,load,resize,scroll,unload,click,dblclick,' +
              'mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,' +
              'mouseleave,change,select,submit,keydown,keypress,keyup,error'
             ).split(',');

jQuery.each(events, function(i, name){
    jQuery.fn['un' + name] = function(){
        return this.unbind(name);
    };
});

#2


jQuery.fn.extend({
      unclick: function() {
        return this.unbind('click');
      }
});

#1


I think you want something like this:

我想你想要这样的东西:

$.fn['unclick'] = function(){
   return this.unbind('click');
};

Now the following two lines are equivalent:

现在以下两行是等价的:

$(...).unbind('click');
$(...).unclick();

For all events (list of events copied from the jQuery source):

对于所有事件(从jQuery源复制的事件列表):

var events = ('blur,focus,load,resize,scroll,unload,click,dblclick,' +
              'mousedown,mouseup,mousemove,mouseover,mouseout,mouseenter,' +
              'mouseleave,change,select,submit,keydown,keypress,keyup,error'
             ).split(',');

jQuery.each(events, function(i, name){
    jQuery.fn['un' + name] = function(){
        return this.unbind(name);
    };
});

#2


jQuery.fn.extend({
      unclick: function() {
        return this.unbind('click');
      }
});