dojo.byId and dijit.byId

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:

dojo. byId ( "breadbox" ). style. fontSize = "72pt";

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

相关文章

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