1.
1 define(['dojo/dom'],function(dom){ 2 var oldText = {}; 3 return { 4 setText:function(id,text){ 5 var node = dom.byId(id); 6 oldText[id] = node.innerHTML; 7 node.innerHTML = text; 8 }, 9 restoreText:function(id){ 10 var node = dom.byId(id); 11 node.innerHTML = oldText[id]; 12 delete oldText[id]; 13 } 14 }; 15 });
2、
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 5 <title>Tutorial: Hello Dojo!</title> 6 </head> 7 <body> 8 <h1 id="greeting">Hello</h1>
//接下来需要配置加载器,其中包含模块位置的信息: 9 <script type="text/javascript"> 10 var dojoConfig = { 11 async:true, 12 packages:[{ 13 name:"demo", 14 location:location.pathname.replace(/\/[^/]*$/,'')+'/demo' 15 }] 16 }; 17 </script> 18 19 <script src="dojo/dojo/dojo.js" data-dojo-config="async: true"></script> 20 <script type="text/javascript"> 21 require(['demo/myModule'],function(myModule){ 22 myModule.setText('greeting','Hello Dojo!'); 23 setTimeout(function(){ 24 myModule.restoreText('greeting'); 25 },3000); 26 }); 27 </script> 28 </body> 29 </html>
3.