本文介绍了如何在mootools上实现一个jQuery live bind事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何通过ajax加载元素,在mootools 1.11上采用与同一个类相关联的事件?
How do I make elements that are loaded via ajax, adopt the events associated with the same class on mootools 1.11?
据我所知,在jQquery中,如果你的ajax响应由< div class ='button'>
之类的东西组成,那么如果有事件绑定使用
到 $('。button')
,这些事件将自动绑定。
As far as I know, in jQquery, if your ajax response consists of something like <div class='button'>
,
if there is an event bind using live
to $('.button')
, those events would automatically bind.
这是可能的MooTools 1.11?
Is that possible with MooTools 1.11?
推荐答案
也许这样做可能会做你想要的?虽然我不知道是否可以使用1.11。
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'); });
这篇关于如何在mootools上实现一个jQuery live bind事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!