当前位置: 首页 > 图文教程 > 网络编程 > Javascript > dojo 之基础篇

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 dojo 之基础篇


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 146 ::
收藏到网摘: n/a

假设我们的工程目录如下:
 -- HelloWorld.html
|-- js/
-- dojo/ /*此处是dojo包下面的文件,列表如下
 -- build.txt
-- CHANGELOG
-- demos
-- ..
-- dojo.js
-- dojo.js.uncompressed.js
-- iframe_history.html
-- LICENSE
-- README
-- src/
现在我们创建HelloWorld.html文件,代码如下:
<html>
<head>
<title>Dojo: Hello World!</title>
<!-- SECTION 1 -->
<script type="text/javascript" src="js/dojo/dojo.js"></script>
<!-- SECTION 2 -->
</head>
<body>
</body>
</html>
在body中加入一个widget button
<button dojoType="Button" widgetId="helloButton">Hello World!</button>
上面不一定要使用widgetId,用平常的id就行了,widget会自己将其转化为widgetId。
以下开始加入section 2的代码。
 <!-- SECTION 2 -->
<script type="text/javascript">
//引入库
//event.*是处理事件,比如:点击,的所有包。
dojo.require("dojo.event.*");
dojo.require("dojo.widget.*");
dojo.require("dojo.widget.Button");
//点击按钮后调用的函数
function helloPressed()
{
alert('You pressed the button');
}
//将helloButton的点击事件绑定到helloPressed()函数
function init()
{
var helloButton = dojo.widget.byId('helloButton');//获得button对象
dojo.event.connect(helloButton, 'onClick', 'helloPressed')//绑定,这只是其中一种绑定方法
}
dojo.addOnLoad(init);//当然也可以将init函数命为其它的名
</script>
这样,就完成了HelloWorld.html的代码. 试试吧.
另外,要注意的是:
如果init函数已经运行了,我们再使用document.getElementById 就没用了. 因为DOM
已经被widget改变. 只能用dojo.widget.byId.