dojo 的DOM操作 dojo/dom
生活随笔
收集整理的這篇文章主要介紹了
dojo 的DOM操作 dojo/dom
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
對(duì)dom的使用,需要引用包dojo/dom。
1.獲取節(jié)點(diǎn), dom.byId
byId中既可以傳遞一個(gè)字符串,也可以傳遞一個(gè)節(jié)點(diǎn)對(duì)象 require(["dojo/dom", "dojo/domReady!"],function(dom) { ????? ????function setText(node, text){ ????????node = dom.byId(node);//通過(guò)已有對(duì)象 ????????node.innerHTML = text; ????} ????var one = dom.byId("one");//通過(guò)字符串 ????setText(one, "One has been set"); ????setText("two", "Two has been set as well"); ????? });
1.獲取節(jié)點(diǎn), dom.byId
byId中既可以傳遞一個(gè)字符串,也可以傳遞一個(gè)節(jié)點(diǎn)對(duì)象 require(["dojo/dom", "dojo/domReady!"],function(dom) { ????? ????function setText(node, text){ ????????node = dom.byId(node);//通過(guò)已有對(duì)象 ????????node.innerHTML = text; ????} ????var one = dom.byId("one");//通過(guò)字符串 ????setText(one, "One has been set"); ????setText("two", "Two has been set as well"); ????? });
<!DOCTYPE html>
<html> <head> <metacharset="utf-8"> <title>Demo: DOM Functions</title> <scriptsrc="//ajax.googleapis.com/ajax/libs/dojo/1.7.8/dojo/dojo.js" data-dojo-config="async: true"> </script> <script> require(["dojo/domReady!"],function() { ? }); </script> </head> <body> <ulid="list"> <liid="one">One</li> <liid="two">Two</li> <liid="three">Three</li> <liid="four">Four</li> <liid="five">Five</li> </ul> </body> </html>// Require the DOM resource
require(["dojo/dom","dojo/domReady!"], function(dom) { ? functionsetText(node, text){ node = dom.byId(node); node.innerHTML = text; } ? varone = dom.byId("one"); setText(one,"One has been set"); setText("two","Two has been set as well"); ? });The arguments to domConstruct.create are as follows: node name as a string, properties of the node as an object, an optional parent or sibling node, and an optional position in reference to the parent or sibling node (which defaults to "last").It returns the new DOM element node. Let's take a look at an example:
require(["dojo/dom","dojo/dom-construct", "dojo/domReady!"],
function(dom, domConstruct) { ? varlist = dom.byId("list"), three = dom.byId("three"); ? domConstruct.create("li", { innerHTML:"Six" }, list); ? domConstruct.create("li", { innerHTML:"Seven", className:"seven", style: { fontWeight:"bold" } }, list); ? domConstruct.create("li", { innerHTML:"Three and a half" }, three,"after"); ? });總結(jié)
以上是生活随笔為你收集整理的dojo 的DOM操作 dojo/dom的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: dojo使用query dojo/que
- 下一篇: 很强大的一个jquery分页插件