Suppose our engineering catalogue is as follows:
--helloworld.html
|--js/
--dojo// * Here is the file below the Dojo package, listed below
--Build.txt
--Changelog
--Demos
-- ..
--Dojo.js
--Dojo.js.uncompressed.js
--iframe_history.html
--LICENSE
--README
--src/
Now we create the helloworld.html file with the following code:
<title>dojo:hello world!</title>
<!--section 1-->
<script type= "Text/javascript" src= "Js/dojo/dojo.js" ></script>
<body>
</body>
Add a widget button to the body
<button dojotype= "button" widgetid= "Hellobutton" >hello world!</button>
The above does not necessarily use Widgetid, with the usual ID on the line, the widget will itself into the Widgetid.
The following starts with section 2 code.
<!--section 2-->
<script type= "Text/javascript" >
Introducing Libraries
Event.* is the handling of events, such as: Click on all the packages.
Dojo.require ("dojo.event.*");
Dojo.require ("dojo.widget.*");
Dojo.require ("Dojo.widget.Button");
function called after clicking the button
function hellopressed ()
{
Alert (' You pressed the button ');
}
Bind the Hellobutton Click event to the hellopressed () function
function init ()
{
var Hellobutton = dojo.widget.byId (' Hellobutton ');//Get Button Object
Dojo.event.connect (Hellobutton, ' OnClick ', ' hellopressed ')/bound, which is just one of the binding methods
}
Dojo.addonload (init); or, of course, the INIT function can be named another name
</script>
This completes the helloworld.html code. Try it.
Also, note that
if the init function is already running, it is useless to use document.getElementById again. Because Dom
has been changed by widgets. You can only use Dojo.widget.byId.