【发布时间】:2011-07-02 07:07:42
【问题描述】:
与 jQuery .live() 等效的 Dojo 是什么?
http://api.jquery.com/live/
我找到的唯一解决方案是 dojo.disconnect 事件处理程序并在将动态标记添加到页面后重新连接它们。
【问题讨论】:
标签: javascript jquery events dojo live
与 jQuery .live() 等效的 Dojo 是什么?
http://api.jquery.com/live/
我找到的唯一解决方案是 dojo.disconnect 事件处理程序并在将动态标记添加到页面后重新连接它们。
【问题讨论】:
标签: javascript jquery events dojo live
用法和demo
dojo.query("body").delegate(selector, eventName, fn);
代码 - 重写了 dojo 原来的 mixin-like delegate 函数
dojo.provide("dojox.NodeList.delegate");
dojo.require("dojo.NodeList-traverse");
dojo.extend(dojo.NodeList, {
delegate: function ( selector,eventName, fn) {
return this.connect(eventName, function (evt) {
var closest = dojo.query(evt.target).closest(selector, this);
if (closest.length) {
fn.call(closest[0], evt);
}
}); //dojo.NodeList
}
});
您可以像 jQuery delegate 一样更普遍地使用它,而不仅仅是 live,因为 live 基本上是文档级别的 delegate。
【讨论】:
delegate 功能应该在 Dojo 1.6 的完整版本中通过要求 dojox.NodeList.delegate 可用(此模块可以在票证末尾的变更集中看到链接在答案中)。如果您好奇,目前可以使用 1.6 RC。 download.dojotoolkit.org/release-1.6.0rc1
我认为 dojo.behavior 执行类似的功能
【讨论】:
随便用
on(document, "xxx", function(){})
例如。在 jquery 中:$(".className").live(function(){})
在道场中,很高兴:on(document, ".className", function(){})
其实jquery.live就是这么做的,就是将事件绑定到文档上来实现功能。
【讨论】: