javascript – 获取DOM元素的dojo方法

我有’this’指向DOM元素(div或表单).我想在该元素上使用dojo函数.我该怎么做

就像在jQuery中我们做$(this).append()….

有没有像

dojo.foo(this).connect() 

要么

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

解决方法:

在Dojo中,你更接近JavaScript(原始金属)而不是jQuery.

所以在Dojo,你只需:

dojo.connect(this, ...);

您不必使用类对象(如jQuery的$)“封装”DOM元素来使用这些功能. Dojo中的许多功能不作为类对象的原型属性公开,而是作为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(...);

阅读文档了解更多详情.

相关文章

我有一个网格,可以根据更大的树结构编辑小块数据.为了更容易...
我即将开始开发一款教育性的视频游戏.我已经决定以一种我可以...
我正在使用带有Grails2.3.9的Dojo1.9.DojoNumberTextBox小部...
1.引言鉴于个人需求的转变,本系列将记录自学arcgisapiforja...
我正在阅读使用dojo’sdeclare进行类创建的语法.描述令人困惑...
我的团队由更多的java人员和JavaScript经验丰富组成.我知道这...