【发布时间】:2011-01-24 01:39:46
【问题描述】:
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'); });
上面的代码是在similar question 中完成的,用于在 Mootools 中实现 .live 行为。我读过这个问题:Prototype equivalent for jQuery live function。
如何在 Prototype 中实现这一点?大概可以这样实现:
document.liveobserve('click', 'a', function(e){ alert('This is a live event');
已编辑以明确问题。
【问题讨论】:
-
老实说,在 mootools 中(尽管这在当前版本中是不稳定的),它现在可以原生/不同地工作,例如:
$('foo').addEvent('click:relay(li)');- 不确定这是否有助于原型。 -
@Dimitar。很高兴知道 +1
标签: prototypejs mootools jquery