
- 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 檔案;您將收到以下輸出 −

廣告