how to implement a jQuery live bind event on mootools?

后端 未结 4 1214
别那么骄傲
别那么骄傲 2020-12-10 00:06

How do I make elements that are loaded via ajax, adopt the events associated with the same class on mootools 1.11?

As far as I know, in jQquery, if your ajax respons

4条回答
  •  情书的邮戳
    2020-12-10 00:26

    Perhaps something like this might do what you're looking for? Though I'm not sure if it'll work with 1.11.

    Element.implement({
        addLiveEvent: function(event, selector, fn){
            this.addEvent(event, function(e){
                var t = $(e.target);
    
                if (!t.match(selector)) return false;
                    fn.apply(t, [e]);
            }.bindWithEvent(this, selector, fn));
        }
    });
    
    $(document.body).addLiveEvent('click', 'a', function(e){ alert('This is a live event'); });
    

提交回复
热议问题