什么是Dojo相当于jQuery .live()? [英] What is the Dojo equivalent to jQuery .live()?

查看:132
本文介绍了什么是Dojo相当于jQuery .live()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是Dojo等效于jQuery .live()?

http://api.jquery.com / live /

What is the Dojo equivalent to jQuery .live()?
http://api.jquery.com/live/

我发现唯一的解决方案是dojo.dis连接事件处理程序,并重新连接它们,一旦将动态的标记添加到

The only solution I found was to dojo.disconnect the event handlers and re-connect them once a dynamic piece of markup was added to the page.

推荐答案

使用 演示

usage and demo

dojo.query("body").delegate(selector, eventName, fn);

代码 - 重写原始的mixin-like delegate dojo的功能

code - rewrites the original mixin-like delegate function of dojo

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
    }
});

请参阅票#11459

您可以更一般地使用这个jQuery delegate ,而不仅仅是 live ,因为 live 基本上是一个代表在文档级别。

You can use this more generally like jQuery delegate, not just as live, because live is basically a delegate on the document level.

这篇关于什么是Dojo相当于jQuery .live()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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