哪些 JavaScript 库具有事件委托?

发布于 2024-07-25 11:34:53 字数 643 浏览 4 评论 0原文

我想尝试一个新的 JavaScript 库。 使用(并且喜欢)jQuery 1.3 的“实时”事件后,我'我更喜欢下一个库,我尝试将事件委托内置到事件系统中。 维基百科的 JS 库比较 在这里完成了这项工作。

看起来 MooTools 正在变得它在 2.0 中。 其他人呢?

我正在制作这个社区维基。 请帮我填写清单。

原型:无

jQuery:从 1.3 开始

MooTools:自 2.0 起

ExtJS:是

I'd like to try out a new JavaScript library. Having used (and loved) jQuery 1.3's "Live" events, I'd prefer the next library I try to have event delegation built in to the event system. Wikipedia's JS Library Comparison falls down on the job here.

Looks like MooTools is getting it in 2.0. What about the others?

I'm making this community wiki. Please help me fill in the list.

Prototype: no

jQuery: as of 1.3

MooTools: as of 2.0

ExtJS: yes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

长不大的小祸害 2024-08-01 11:34:53

事件委托比您想象的要容易。

如果我发现一个没有自动事件委托的库,我只需向它添加一个层。

Event delegation is easier than you think.

If I find a library without automatic event delegation, I just add a layer to it.

錯遇了你 2024-08-01 11:34:53

我建议查看 Prototype。 它在 SO 上的列出频率与 jQuery 一样频繁,我将它用作我所有项目的 JS 库。

我不相信它内置了代表,但它是一个功能齐全的库,具有根据需要添加代表所需的所有必要功能。

I'd suggest looking into Prototype. It is listed on SO about as frequently as jQuery and I use it as my JS library for all my projects.

I don't believe it has delegates built in but it is a full featured library with all the necessary functionality to add delegates to as needed.

眼波传意 2024-08-01 11:34:53

如果您喜欢使用 Jquery 但想尝试一些不同的东西,我会选择 mootools,Aarons 事件委托插件的链接以及他关于如何使用原始插件的教程应该可以满足您所需的一切。 关于哪一个更好的讨论很多,归根结底,这只是你更喜欢的。

Mootools 非常出色,并且有一些很好的插件,您还应该看看 David Walsh,他做了很多 mootools 开发和一些 Jquery。 他发布了一些有趣的东西。
http://davidwalsh.name

If you love using Jquery but fancy trying something different I would go with mootools, the link to Aarons event delegation plugin plus his tutorial on how to use the original should give you all you need. There is a lot of discussion about which is better at the end of the day its just what you prefer.

Mootools is excellent and has some good plugins, you should also check out David Walsh who does a lot of mootools dev and some Jquery. He posts some interesting stuff.
http://davidwalsh.name

聊慰 2024-08-01 11:34:53

事件委托只是将事件处理程序挂在 DOM 树上。 所有框架都可以/应该能够做到这一点。 处理程序应该能够拾取任何冒泡的事件。 该事件包含触发它的元素,处理程序可以根据该元素执行任何操作。

Prototype 没有任何像 jQuery 的 $.fn.live 一样工作的库本机事件委托糖,但构建一个捕获事件并对其目标元素执行操作的函数相当简单。

document.observe('click',function(event){alert(event.element().inspect())})

你可以使用它来非常轻松地克隆 jQuery 的 live(我并不是说这会表现良好或其他什么)。

live = function(selector,callback){
  document.observe("click",function(e){
    var element = e.element()
    if (!element.match(selector))
      element = element.ancestors().find(function(elem){return elem.match(selector)});
    else
      element = null
    if (element)
      callback.apply(element)
  })
}

你可以这样称呼它:

live("div",function(){this.setStyle({color:'blue'})})

我想我想说的是事件委托已经内置在 javascript 中了。 图书馆只是添加糖。

Event delegation is just about hanging event handlers further up the DOM tree. All of the frameworks can/should be able to do that. The handlers should be able to pickup any event that bubbles. The event contains the element that triggered it, and from that the handler can do whatever.

Prototype doesn't have any event delegation sugar native to the library that works like jQuery's $.fn.live, but it is fairly simple to build a function that catches events and does stuff with their target elements.

document.observe('click',function(event){alert(event.element().inspect())})

You can use this to make a clone of jQuery's live pretty easily(I am not saying this will perform well or anything).

live = function(selector,callback){
  document.observe("click",function(e){
    var element = e.element()
    if (!element.match(selector))
      element = element.ancestors().find(function(elem){return elem.match(selector)});
    else
      element = null
    if (element)
      callback.apply(element)
  })
}

You could call it like:

live("div",function(){this.setStyle({color:'blue'})})

I guess what I am saying is that event delegation is built in to javascript already. Libraries just add sugar.

迷乱花海 2024-08-01 11:34:53

Ext Js 始终是我相信的。

Ext Js always has I believe.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文