- RequireJS 教程
- RequireJS - 主页
- RequireJS - 概述
- RequireJS - 环境设置
- RequireJS - 配置
- RequireJS - AMD 模块
- RequireJS - 定义函数
- RequireJS - 优化器
- RequireJS - jQuery
- RequireJS - NodeJS
- RequireJS - Dojo
- RequireJS - CommonJS
- RequireJS - 插件
- RequireJS 有用资源
- RequireJS - 快速指南
- RequireJS - 有用资源
- RequireJS - 讨论
RequireJS - Dojo
Dojo 是一种 JavaScript 工具包,它基于 AMD 模块架构,该架构提供额外的模块以向 Web 应用程序添加额外功能,同时还节省了 Web 应用程序开发过程中的时间和规模。
示例
以下示例显示了 Dojo 与 RequireJS 一起使用的用法。创建一个名为 index.html 的 html 文件,并向其中放置以下代码 −
<!DOCTYPE html>
<html>
<head>
<title>RequireJS Dojo</title>
<script data-main="app" src="lib/require.js"></script>
</head>
<body>
<h2>RequireJS Dojo</h2>
<p>
Hello... ...
</p>
</body>
</html>
创建一个名为 app.js 的 js 文件,并向其中添加以下代码 −
require ({
//You can configure loading modules from the lib directory
baseUrl: 'lib',
paths: {
//mapping of package
dojo: 'http://sfoster.dojotoolkit.org/dojobox/1.7-branch/dojo'
}
}, [
//modules which we are using here
'dojo/dom'
], function(dom) {
//using the 'byId' method from dom module
var mydojo = dom.byId('dojo_val')
mydojo.innerHTML = "The text is displaying via dojo/dom";
}
);
输出
在浏览器中打开 HTML 文件;您将收到以下输出 −
广告