dojo/dom dojo/domConstruct dojo/query
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.destroywhich will destroy a node and all of its childrendomConstruct.emptywill 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
queryreturns an array of nodes that match the selector; this array is actually adojo/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的更多相关文章
- Dojo初探之4:dojo的event(鼠标/键盘)事件绑定操作(基于dojo1.11.2版本)
前言: 上一章详解了dojo的dom/query操作,本章基于dom/query基础上进行事件绑定操作 dojo的事件 dojo的事件绑定操作分为鼠标和键盘两种进行详解 1.鼠标事件 我们沿用上一章中 ...
- Dojo初探之3:dojo的DOM操作、query操作和domConstruct元素位置操作(基于dojo1.11.2版本)
前言: 前面两章讲了dojo的基本规范和配置,当然这个配置不是必须的,当你有这需求的时候就可以用到dojo的config配置. dojo的所有js都是符合AMD规范进行异步加载的:http://blo ...
- DOJO DOM 功能
In this tutorial, you'll learn about how to use Dojo to manipulate the DOM in a simple, cross-browse ...
- dojo 七 DOM dojo/dom
官方教程:Dojo DOM Functions对dom的使用,需要引用包dojo/dom.1.获取节点,dom.byIdbyId中既可以传递一个字符串,也可以传递一个节点对象 require([&qu ...
- dojo/dom源码学习
dojo/dom模块作为一个基础模块,最常用的就是byId方法.除此之外还有isDescendant和setSelectable方法. dom.byId(myId)方法: 各种前端类库都免不了与D ...
- dojo/dom源码
dojo/dom源码学习 dojo/dom模块作为一个基础模块,最常用的就是byId方法.除此之外还有isDescendant和setSelectable方法. dom.byId(myId)方法: ...
- Dojo初探之5:dojo的request(请求)操作、请求过程事件绑定和隐藏数据data()操作(基于dojo1.11.2版本)
前言: 上一章详细阐述了dojo的事件绑定操作,本章将讲解dojo的请求操作 注:dojo的请求操作与js和jquery完全不同! 1.dojo的请求 dojo通过request.get()/.put ...
- Configuring Dojo with dojoConfig - The Dojo Toolkit
转载自Dojo官网 Configuring Dojo with dojoConfig The dojoConfig object (formerly djConfig) allows you to s ...
- dojo/Deferred类和dojo/promise类的使用
参考博客:https://blog.csdn.net/blog_szhao/article/details/50220181 https://dojotoolkit.org/docume ...
随机推荐
- opengl 3.3 tutorial
http://www.mbsoftworks.sk/index.php?page=tutorials&series=1
- 详解Java中的clone方法:原型模式
转:http://developer.51cto.com/art/201506/478985.htm clone顾名思义就是复制, 在Java语言中, clone方法被对象调用,所以会复制对象.所谓的 ...
- string函数分析
string函数分析string函数包含在string.c文件中,经常被C文件使用.1. strcpy函数原型: char* strcpy(char* str1,char* str2);函数功能: 把 ...
- ICP算法使用遇到的问题
这几天在学习数据关联的方法,本来想使用ICP算法进行距离测距数据的配准,但是用的过程中出现问题,配的不准,而且偏差更大了. 红色的和黄色的2维激光点进行ICP配准,但将变换矩阵和黄色进行乘之后偏差更大 ...
- oracle恢复备份数据
sqlplus链接数据库: 1.sqlplus 用户名/密码@IP地址/数据库名称 2.sqlplus 用户名/密码@数据库名称 注:第二种方法要在tnsnames.oRA文件中配置数据库名称 链接断 ...
- How to debug PostgreSQL function with pgAdminIII
How to debug plpgsql with pgAdminIII [root@localhost soft_bak]# git clone git://git.postgresql.org/g ...
- 监控linux服务器网卡流量
监控linux服务器网卡流量 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 欢迎加入:高级运维工程师之路 598432640 前言:众所周知,我们安装zabbix服务器 ...
- How to export a template in Visual Studio?
Create a customize template file: 1.template arguments introduction like: 上图只是其中一部分,更多请查看文后的参考资源 tem ...
- [转]easyui data-options的使用
原文地址:easyui data-options的使用 data-options是jQuery Easyui 最近两个版本才加上的一个特殊属性.通过这个属性,我们可以对easyui组件的实例化可以完全 ...
- C++之路进阶——bzoj3172(单词)
F.A.Qs Home Discuss ProblemSet Status Ranklist Contest ModifyUser hyxzc Logout 捐赠本站 Notice:由于本OJ建立在 ...