dom.byId

require(["dojo/dom", "dojo/domReady!"], function(dom) {
var one = dom.byId("one");
function setText(node, text){
node = dom.byId(node);
node.innerHTML = text;
}
setText(one, "One has been set");
setText("two", "Two has been set as well");
});

domConstruct.create

  • parameters

    • node name,
    • properties of the node(json),
    • parent/sibling node,
    • optional position in ref to the parent/sibling node (last by default)
  • example

require(["dojo/dom", "dojo/dom-construct", "dojo/domReady!"], function(dom, domConstruct) {
var list = dom.byId("swlist");
domConstruct.create("li", {
innerHTML: "Seven",
className: "seven",
style: {
fontWeight: "bold"
}
}, list);
// or
domConstruct.create("li", {
innerHTML: "Three and a half"
}, list, "after"); });

domConstruct.place

  • parameters

    • node to place,
    • node as a reference,
    • optional position (last by default)
  • example

require(["dojo/dom", "dojo/dom-construct", "dojo/on", "dojo/domReady!"], function(dom, domConstruct, on) {
function moveFirst(){
var list = dom.byId("list"),
three = dom.byId("three"); domConstruct.place(three, list, "first");
// 把three place到list的第一个位置
// "before", "after", "replace", "only", "first", 以及 "last"
}
on(dom.byId("moveFirst"), "click", moveFirst);
});

domConstruct.destory domConstruct.empty

  • the same as jQuery
  • domConstruct.destroy which will destroy a node and all of its children
  • domConstruct.empty will only destroy the children of a given node
  • example
require(["dojo/dom", "dojo/dom-construct", "dojo/on", "dojo/domReady!"], function(dom, domConstruct, on) {
function destroyFirst(){
var list = dom.byId("list"),
items = list.getElementsByTagName("li"); if(items.length){
domConstruct.destroy(items[0]);
}
}
on(dom.byId("destroyFirst"), "click", destroyFirst);
});

query from dojo/query

  • query returns an array of nodes that match the selector; this array is actually a dojo/NodeList
require(["dojo/query", "dojo/dom-class", "dojo/dom", "dojo/NodeList-dom", "dojo/domReady!"], function (query, domClass, dom) {
// retrieve an array of nodes with the class name "odd"
// from the first list using a selector
var odds1 = query("#list .odd");
// retrieve an array of nodes with the class name "odd"
// from the first list using a DOM node
// same as above
var odds2 = query(".odd", dom.byId("list"));
// retrieve an array of nodes with the ID "list"
var list = query("#list")[0]; query(".odd").forEach(function(node, index, nodelist){
// for each node in the array returned by query,
// execute the following code
domClass.add(node, "red");
});
// `forEach` is a function from `NodeList'
// `map`, `filter`, `every`, and `some` (also return a NodeList fro easy chaining)
// `dojo/NodeList-dom` extends `NodeLists`
query(".odd").addClass("active");
query(".odd").removeClass("active").addClass("dimmed");
query(".even").style("color", "white").addClass("italic");
// funtions from NodeList-dom `style`, `toggleClass`, `replaceClass`, `place`, and `empty`, `addClass`, `removeClass`
// a `on` function is provided in `NodeList`
query(".hookUp").on("click", function(){
alert("This button is hooked up (via NodeList on method) !");
});
});

dojo/dom dojo/domConstruct dojo/query的更多相关文章

  1. Dojo初探之4:dojo的event(鼠标/键盘)事件绑定操作(基于dojo1.11.2版本)

    前言: 上一章详解了dojo的dom/query操作,本章基于dom/query基础上进行事件绑定操作 dojo的事件 dojo的事件绑定操作分为鼠标和键盘两种进行详解 1.鼠标事件 我们沿用上一章中 ...

  2. Dojo初探之3:dojo的DOM操作、query操作和domConstruct元素位置操作(基于dojo1.11.2版本)

    前言: 前面两章讲了dojo的基本规范和配置,当然这个配置不是必须的,当你有这需求的时候就可以用到dojo的config配置. dojo的所有js都是符合AMD规范进行异步加载的:http://blo ...

  3. DOJO DOM 功能

    In this tutorial, you'll learn about how to use Dojo to manipulate the DOM in a simple, cross-browse ...

  4. dojo 七 DOM dojo/dom

    官方教程:Dojo DOM Functions对dom的使用,需要引用包dojo/dom.1.获取节点,dom.byIdbyId中既可以传递一个字符串,也可以传递一个节点对象 require([&qu ...

  5. dojo/dom源码学习

    dojo/dom模块作为一个基础模块,最常用的就是byId方法.除此之外还有isDescendant和setSelectable方法. dom.byId(myId)方法:   各种前端类库都免不了与D ...

  6. dojo/dom源码

    dojo/dom源码学习   dojo/dom模块作为一个基础模块,最常用的就是byId方法.除此之外还有isDescendant和setSelectable方法. dom.byId(myId)方法: ...

  7. Dojo初探之5:dojo的request(请求)操作、请求过程事件绑定和隐藏数据data()操作(基于dojo1.11.2版本)

    前言: 上一章详细阐述了dojo的事件绑定操作,本章将讲解dojo的请求操作 注:dojo的请求操作与js和jquery完全不同! 1.dojo的请求 dojo通过request.get()/.put ...

  8. Configuring Dojo with dojoConfig - The Dojo Toolkit

    转载自Dojo官网 Configuring Dojo with dojoConfig The dojoConfig object (formerly djConfig) allows you to s ...

  9. dojo/Deferred类和dojo/promise类的使用

    参考博客:https://blog.csdn.net/blog_szhao/article/details/50220181        https://dojotoolkit.org/docume ...

随机推荐

  1. ORACLE十进制与十六进制的转换

    十进制与十六进制的转换 十进制-->十六进制 select to_char(100,'XX') from dual; 十六进制-->十进制select to_number('7D','XX ...

  2. 给网卡配置10个临时ip地址,但是不配置192.168.17.15这个ip

    给网卡配置10个临时ip地址,但是不配置192.168.17.15这个ip #!/bin/bash `;do ];then continue fi ifconfig eth0:$i .$i netma ...

  3. 详解Java中的clone方法:原型模式

    转:http://developer.51cto.com/art/201506/478985.htm clone顾名思义就是复制, 在Java语言中, clone方法被对象调用,所以会复制对象.所谓的 ...

  4. WebApi 找到了与该请求匹配的多个操作

    在同一个命名空间内,报错 错误的路由代码: namespace CRM4S { public static class WebApiConfig { public static void Regist ...

  5. selenium 基本了解

    Selenium的界面 白色:还未执行 浅青色:动作成功 深青色:判断成功 浅粉红色:判断失败,但不影响测试案例的运行 深粉红色:判断失败,且测试案例无法正常运行 Command 存在的命令 Acti ...

  6. 转:CDC,CPaintDC,CClientDC,CWindowDC区别

    http://www.cnblogs.com/songsu/articles/1350014.html

  7. 关闭ehcache的更新检查UpdateChecker

    ehcache默认开启自动更新检查,在你不能联网的环境下,会有异常出现. 在ehcache的配置文件中ehcache标签上加上属性updateCheck="false" 即可.

  8. Oracle RAC 11.2.0.4 – RHRL 6.4: DiskGroup resource are not running on nodes. Database instance may not come up on these nodes

    使用DBCA创建新库的时候报错: 查看资源状态: $ crsctl stat res -t ------------------------------------------------------ ...

  9. C++字符串(String)

    字符串的声明: string s; string str="abcdefg"; char ch[]="abcdefg"; //使用string类型初始化另一个s ...

  10. android与后台请求的例子

    public static ClientResponse SendClientRequest(List<BasicNameValuePair> params){ ClientRespons ...