dojo.byId(String id)
This function is a synonym for document.all.id in IE or document.getElementById(id) in standard DOM. So you can say:
If document.getElementById() works in all modern browsers,why use this? Sadly,bugs persist in Internet Explorer which make getElementById() unstable in some common scenarios. Also,dojo.byId() is easier to type.
dijit.byId(String id)
Because of the almost-identical spelling,this method is commonly mixed up with dojo.byId(String id). Here's the difference: dijit.byId() returns a Dijit widget instance - technically,an instance of dijit._Widget or one of its subclasses like dijit.Toolbar or dijit.TreeNode.
So here's the way to remember it:
- If you need a DOM Node,use dojo.byId. You need a DOM node anytime you call a standard browser function,change a standard property,etc.
- If you need a widget,use dijit.byId. From it you can access all of the attributes,methods and extension points listed in Part 2.
Or for you who think in terms of functions (e.g. LISP programmers?):
var myDomNode = dojo.byId("foo"); var myWidget = dijit.byId("foo"); console.debug(myDomNode == myWidget.domNode); // true console.debug(dijit.byNode(myDomNode) == myWidget); // true
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。