原型相当于jQuery live功能 [英] Prototype equivalent for jQuery live function
本文介绍了原型相当于jQuery live功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在jQuery中,这将是
$(。foo)。live(click,function(e){
// bar
});
在这种原型中是否有等价物?
解决方案
通常使用事件#findElement
:
document.observe('click',function(e,el){
if(el = e.findElement('。foo')){
//有你的'el'
//可能想在这一点停止事件 - e.stop()
}
});
I need to bind event listener to all dynamicaly created elements by given css selector.
In jQuery, that would be
$(".foo").live("click", function(e) {
// bar
});
Is there any equivalent in Prototype for this?
解决方案
This is usually done with Event#findElement
:
document.observe('click', function(e, el) {
if (el = e.findElement('.foo')) {
// there's your `el`
// might want to stop event at this point - e.stop()
}
});
这篇关于原型相当于jQuery live功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文