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. JavaScript:复选框事件的处理

    复选框事件的处理 复选框本身也是多个组件的名字相同.所以在定义复选框的同事依然要使用document.all()取得全部的内容. 范例:操作复选框,要求是可以一个个去选择选项,也可以直接全选,全选按钮 ...

  2. mongoose的promise(转发)

    Switching out callbacks with promises in Mongoose Published on July 28, 2015 mongo node mongoose pro ...

  3. CentOS 6.6 yum 搭建LAMP环境

    CentOS 查看操作系统版本 [root@oa ~]# cat /etc/redhat-releaseCentOS release 6.6 (Final) 参考linux centos yum安装L ...

  4. Basic认证

    Basic 概述 Basic 认证是HTTP 中非常简单的认证方式,因为简单,所以不是很安全,不过仍然非常常用. 当一个客户端向一个需要认证的HTTP服务器进行数据请求时,如果之前没有认证过,HTTP ...

  5. 学习 Log4net

    遇到问题: 开发机器:WINDOWS 8, 英文版, 64位 在实际使用中发现,写在文件中的中文全部变成乱码(变成问号). 解决方法: <appender name="FileAppe ...

  6. ORA-16179: incremental changes to "log_archive_dest_1" not allowed with SPFILE

    SQL> alter system set log_archive_dest_1='E:\arch ' scope=both; alter system set log_archive_dest ...

  7. svn合并

    1.先去 aone里我的变更 里 重建 新分支 相当于重主干上拉代码下来2.然后再去 原来的分支里 swich切换到新分支3.在原来的分支里 merge 到新分支的url4.选择最早的 version ...

  8. Cocoapods注意点

    1 安装和升级$ sudo gem install cocoapods $ pod setup 2 更换为taobao的源 $ gem sources -r https://rubygems.org/ ...

  9. C++Primer 第十八章

    //1.异常:待研究 //2.命名空间: // A:多个库将名字放置在全局命名空间中将引发命名空间污染. // B:命名空间为防止名字冲突提供了更加可控的机制.命名空间分割了全局命名空间,其中每个命名 ...

  10. VCL Tclientsocket, Tserversocket控件安装方法

    菜单component->Install Packets 按Add按钮,选择delphi目录里的bin目录下的dclsockets70.bpl(delphi2010是dclsockets140. ...