dojo.byId
来源:互联网 发布:广联达预算软件官网 编辑:程序博客网 时间:2024/05/12 07:35
dojo.byId
Contents
- Examples
- Fade-out a node
- See Also
- References
This is a simple alias to ''document.getElementById'', which notonly is shorter to write, but fortunately works in all browsers. Itturns a domNode reference to some Node byId, or the same node referenceif passed a domNode.
1
2
// fetch a node by id="someNode"
var node = dojo.byId("someNode");
The node variable is just a native domNode, with properties you can manipulate. The most common, ''innerHTML'':
1
2
// set some node to say "Hello World"
dojo.byId("someNode").innerHTML = "Hello World";
If you pass byId a domNode reference, the same node is returned:
1
2
3
4
var node = dojo.byId("someNode");
var other = dojo.byId(node);
console.log(node == other);
>>> true
If you pass dojo.byId a string, and nodomNode is found to match, ''undefined'' or the null object is returned(depending on the browser), which is adequate truthiness to useconditionally:
1
2
3
4
5
6
var node = dojo.byId("fooBar");
if(node){
node.innerHTML = "I was found!";
}else{
console.log("no node with id='fooBar' found!");
}
Most (if not all) functions in Dojo accepteither a string or DomNode as a parameter. If passed a string, thefunction typically calls dojo.byId(), ensuring a domNode is always theobject. For instance:
1
2
3
dojo.style(dojo.byId("foo"), "opacity", 0.5);
// is identical to:
dojo.style("foo", "opacity", 0.5);
The latter is preferred, as the call todojo.byId is made in both cases. The passing of a string ID isconsistent throughout the Dojo Toolkit.
JavaScript has a fun convention for conditionals inline. Imaginewanting a domNode reference, and if not present, default to some othernode:
1
2
3
var othernode = dojo.byId("fallbackNode");
var node = dojo.byId("missingNode") || othernode;
node.innerHTML = "Which one?";
Above, if the node id="missingNode" is in fact missing, the logical OR will continue, and use othernode as the value of node.
Examples
Fade-out a node
The following example lets a node by id dissapear from the screen
See Also
- dijit.byId - Accessing a Dijit widget by id.
References
- DOM - Official documentation on the Document Object Model.
- dojo.byId
- dojo.byId与registry.byId、dijit.byId
- dojo.byId and dijit.byId
- dojo.byId and dijit.byId
- dojo.byId viewDemo
- Dojo学习:dijit.byId与dojo.byId的区别
- data-dojo-id, dijit/registry.byId() and dojo/dom.byId()
- dojo 学习笔记之一 dom.byId dojo.byId registry.byId 的区别
- dojo.byId() dijit.byId() & jsId的区别与联系
- dojo.byId() dijit.byId() & jsId的区别与联系
- dojo041中dojo.byId存在问题
- byId
- IdentifierLoadAccess and Session.byId()
- dojo
- dojo
- Dojo
- dojo
- dojo
- 互联网创业团队需要什么样的人
- Linux上设置静态网络配置,ip/gateway/DNS
- 生成有意义随机的文本(学习文档的K阶马尔科夫链)。--- 编程珠玑
- 联动菜单
- IT工程师必看的十条建议
- dojo.byId
- 深入解析windows XP/2003:内核模式和用户模式
- 个人电脑常见的被入侵方式
- 2009互联网大会-赵中捷报道
- 制作应用程序(.bat)
- VSS 错误 "Error reading from file" 的修复方法
- Excel 读取数据,日期读取
- oracle常用命令收集中
- 思想开放-学数学之人必备的特质(转载)