dojo 的一些简单例子
http://dojotoolkit.org/documentation/tutorials/1.6/hello_dojo/
Hello Dojo!Welcome! In this tutorial,we'll start from the ground up,with a simple HTML page. By the end of this tutorial,we'll have loaded Dojo into the page,as well as put some of the core functions to work. We'll touch on Dojo's modular structure,and discuss how to load dependencies into the page to make a richer experience.
Getting StartedOur starting point is a simple HTML page. We want to load Dojo into the page and add some code to signal our success.
This is as vanilla as it gets. We've put the Dojo script tag into the <head> — it could also have gone at the end of the <body> — with a src attribute indicating the URL where the dojo.ready Readiness,as it relates to an HTML page and the browser,can be a slippery moment to pin down. We need both the DOM to be ready for manipulation,and Dojo (and any indicated dependencies — more on that in a minute) to be loaded before any of our JavaScript code runs. Becausereadyhas different meanings in different browsers,Dojo provides a reliable,cross-browser function for the purpose:
6
7
12
13
14
15
16
17
|
<!-- load Dojo -->
<script>
dojo.ready(
function
(){
alert(
"Dojo version "
+ dojo.version +
" is loaded"
);
});
</script>
>
>
>
>
>
|
dojo.ready
should cause an alert box to pop up when the page loads. Handily,Dojo has a version property that's useful for demos like this. As we get further into learning Dojo,the alert is going to get increasingly annoying,and we'll want to learn about logging to a browserconsole. But for now,we'll stay focused,and move on.
Loading Dojo is great,however it's more likely that you want to manipulate the page you just loaded Dojo into. We'll be digging into this in much more detail in other tutorials. For now,though,we'll simply get a reference to our <h1> and update its content.
"greeting"
).innerHTML +=
",from "
+ dojo.version;
>