javascript - 获取 DOM 元素的 dojo 方法

标签 javascript dojo

我将“this”指向 DOM 元素(divform)。我想对该元素使用 dojo 函数。我将如何做。

就像在 jQuery 中一样,我们执行 $(this).append() ....

有没有类似的东西

dojo.foo(this).connect() 

dojo.connect(dojo.foo(this),"some", thing);

最佳答案

在 Dojo 中,您比在 jQuery 中更接近 JavaScript(原始金属)。

所以在 Dojo 中,你只需要做:

dojo.connect(this, ...);

您不必使用类对象(如 jQuery 的 $)“包装”DOM 元素来使用这些功能。 Dojo 中的很多功能并没有暴露为类对象的原型(prototype)属性,而是暴露为 dojo.xxx 命名空间系统下的简单函数。

例如(假设“this”指向一个DOM节点):

dojo.connect(this, "onclick", foo, "bar");   // Connects a handler to the Click event on the DOM node, with the context (i.e. this) set to the object foo
dojo.attr(this, "href", "http://www.hello.com");   // Sets an attribute on the DOM node
dojo.style(this, "display", "none");   // Sets the DOM node's style
dojo.addClass(this, "hello");   // Adds a class to the DOM node
alert(this.parentNode);   // You work the DOM nodes with raw JavaScript
dojo.empty(this);  // Empty all children in the DOM node
dojo.destroy(this);  // Destroy the DOM node and its children
dojo.place(this, someOtherNode);   // Put a DOM node as a child inside another node

循环构造:

dojo.forEach(array, ...);   // Instead of array.each(...) as in jQuery style

如果你想遍历一个节点列表,它实际上看起来像 jQuery:

dojo.query('query string').filter(...).forEach(...);

阅读文档了解更多详情。

关于javascript - 获取 DOM 元素的 dojo 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6404136/

相关文章:

javascript - Node.js 调用 json 数据时出现问题

javascript - 找不到入口模块 : Error: Can't resolve './src/index.js'

javascript - 使用javascript显示隐藏的div

javascript - Dojo ToggleButton 检查图标未更新

javascript - Dijit 中的文本字段组

javascript - 链式 promise 不会传递拒绝

javascript - 关闭和这个澄清?

javascript - 在 Mocha 测试中绕过 ESLint 的 `no-unused-var` for Should

javascript - 我可以在没有 Cufon 的情况下在 Raphael 中使用打印吗?

javascript - 使用 dojo 移动和重新排序 div