我有’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(...);
阅读文档了解更多详情.
原文地址:https://codeday.me/bug/20190614/1236772.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。