将事件添加到动态生成的元素
如何向 AJAX 加载的元素添加事件。
jQuery 有 live
,但是 Mootools 的等价物是什么?
例如:
window.addEvent('domready', function() {
// some code which loads new elements by ajax
// Filter
$$('.filterButton').addEvent('click', function(event) {
alert('wow');
});
});
How can I add an event to an element which was loaded by AJAX.
jQuery has live
, but what's the Mootools equivalent?
For example:
window.addEvent('domready', function() {
// some code which loads new elements by ajax
// Filter
$('.filterButton').addEvent('click', function(event) {
alert('wow');
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
mootools 的等效方法是通过
delegatorElement.addEvent("event:relay(mask)", fn);
其中event
可以是标准冒泡(单击、鼠标悬停/退出/离开/输入等)或非冒泡(模糊、聚焦、更改等)。在您的代码中,如下所示:
最好将事件添加到 dom 上方的元素,例如
document.id("delegatorId")
更多信息:
http://mootools.net/docs/core/Element/Element.Delegation
请记住,事件委托位于 mootools-核心自1.4 - 在此之前它曾经位于 mootools-more 中,这意味着自定义构建。
the mootools equivalent is via
delegatorElement.addEvent("event:relay(mask)", fn);
whereevent
can be standard bubbling (click, mouseover/out/leave/enter etc) or non-bubbling (blur, focus, change etc).in your code that goes as:
it's better to add the event to an element higher up the dom, like
document.id("delegatorId")
more here:
http://mootools.net/docs/core/Element/Element.Delegation
keep in mind, event delegation is in mootools-core since 1.4 - it used to be in mootools-more before that, which means a custom build.