开发者

Event binding in MooTools like jQuery

Is there a way to assign a multiple event types in MooTools like jQuery?

Mootools:
$$('#id').addEvents({
    keyup: fn,
    click: fn
});

jQuery:
$('#id).b开发者_开发技巧ind('keyup click' ,fn);


Yes, there is a way, through the powerful implement:

Element.implement({
    fakeBind : function(evtsStr, callback){
        var events = evtsStr.split(' '), 
            i = 0, 
            l = events.length;
        for (; i < l; i++){
            this.addEvent(events[i], callback);
        }
    }
});

$$('div.myClass').fakeBind('click mouseleave', function(event){
    console.log(event.type);
});

Demo


Its not much, but have a look at this: http://ryanflorence.com/jquery-1-4-mootools-1-2-compared/#binding-multiple-events

In this article Jquery 1.4 and mootools 1.2 are compared, and they really look alike..

Im afraid i can't think of any way that mootools can do that..

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜