Home  >  Article  >  Web Front-end  >  The basics of dojo_dojo

The basics of dojo_dojo

WBOY
WBOYOriginal
2016-05-16 19:16:221927browse

Assume that our project directory is as follows:

<pre class="brush:php;toolbar:false">   -- HelloWorld.html<br><br>  |-- js/<br><br>     -- dojo/  /*此处是dojo包下面的文件,列表如下<br><pre class="brush:php;toolbar:false">       		 -- build.txt<br>       		 -- CHANGELOG<br>      		 -- demos<br><br>         		  -- ..<br>       		 -- dojo.js<br>       		 -- dojo.js.uncompressed.js<br>       		 -- iframe_history.html<br>       		 -- LICENSE<br>       		 -- README<br>       		 -- src/<br><br> 
Now we create the HelloWorld.html file with the following code:
<pre class="brush:php;toolbar:false"><html><br> <head><br>  <title>Dojo: Hello World!</title><br><br>  <!-- SECTION 1 --><br>  <script type="text/javascript" src="js/dojo/dojo.js"></script><br><br>  <!-- SECTION 2 --> <br> </head><br><br> <body><br> </body><br></html>
Add a widget button to the body
<pre class="brush:php;toolbar:false"><button dojoType="Button" widgetId="helloButton">Hello World!</button><br><br>上面不一定要使用widgetId,用平常的id就行了,widget会自己将其转化为widgetId。<br>
Start adding the code for section 2 below.
<pre class="brush:php;toolbar:false">  <!-- SECTION 2 --><br>  <script type="text/javascript"><br><br>   //引入库<br>   //event.*是处理事件,比如:点击,的所有包。<br>   dojo.require("dojo.event.*");<br>   dojo.require("dojo.widget.*");<br>   dojo.require("dojo.widget.Button");<br><br>   //点击按钮后调用的函数<br>   function helloPressed()<br>   {<br>    alert('You pressed the button');<br>   }<br><br>   //将helloButton的点击事件绑定到helloPressed()函数<br>   function init()<br>   {<br>    var helloButton = dojo.widget.byId('helloButton');//获得button对象<br>    dojo.event.connect(helloButton, 'onClick', 'helloPressed')//绑定,这只是其中一种绑定方法<br>   }<br><br>   dojo.addOnLoad(init);//当然也可以将init函数命为其它的名<br>  </script><br>
<pre class="brush:php;toolbar:false">这样,就完成了HelloWorld.html的代码. 试试吧.<br><br>另外,要注意的是:<br>如果init函数已经运行了,我们再使用<code>document.getElementById</code> 就没用了. 因为DOM<br>已经被widget改变. 只能用dojo.widget.byId.<br>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn