等效于 jQuery 实时功能的原型 [英] Prototype equivalent for jQuery live function

查看:30
本文介绍了等效于 jQuery 实时功能的原型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过给定的 css 选择器将事件侦听器绑定到所有动态创建的元素.

I need to bind event listener to all dynamicaly created elements by given css selector.

在 jQuery 中,那就是

In jQuery, that would be

$(".foo").live("click", function(e) {
   // bar
});

原型中是否有与此相同的内容?

Is there any equivalent in Prototype for this?

推荐答案

这通常通过 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 实时功能的原型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆