这是我从文章中获取的示例,并进行了一些更改。这个例子完美地工作
<!DOCTYPE HTML>
<html lang="en">
<head>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.8.3/dijit/themes/claro/claro.css" media="screen">
<script type="text/javascript">
dojoConfig = {
parseOnLoad: false,
async: true
};
</script>
<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.8.3/dojo/dojo.js" type="text/javascript"></script>
<script type="text/javascript">
/// Require the registry, parser, Dialog, and wait for domReady
require(["dijit/registry", "dojo/parser", "dojo/json", "dojo/_base/config", "dijit/Dialog"], function (registry, parser, JSON, config) {
// Explicitly parse the page
parser.parse();
// Find the dialog
var dialog = registry.byId("dialog");
// Set the content equal to what dojo.config is
dialog.set("content", "<b>it works!</b>");
// Show the dialog
dialog.show();
});
</script>
</head>
<body class="claro">
<div id="dialog" data-dojo-type="dijit.Dialog"></div>
</body>
</html>
现在我想修改它并使用 jQuery 动态加载 Dojo。这是我如何执行此操作的示例:
<!DOCTYPE HTML>
<html lang="en">
<head>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.8.3/dijit/themes/claro/claro.css" media="screen">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
dojoConfig = {
parseOnLoad: false,
async: true
};
$.getScript("http://ajax.googleapis.com/ajax/libs/dojo/1.8.3/dojo/dojo.js")
.done(function (script, textStatus) {
/// Require the registry, parser, Dialog, and wait for domReady
require(["dijit/registry", "dojo/parser", "dojo/json", "dojo/_base/config", "dijit/Dialog"], function (registry, parser, JSON, config) {
// Explicitly parse the page
parser.parse();
// Find the dialog
var dialog = registry.byId("dialog");
// Set the content equal to what dojo.config is
dialog.set("content", "<b>it works!</b>");
// Show the dialog
dialog.show();
});
})
.fail(function (jqxhr, settings, exception) {
alert('Cannot load Dojo.js');
});
});
</script>
</head>
<body class="claro">
<div id="dialog" data-dojo-type="dijit.Dialog">
</div>
</body>
</html>
但看起来我做错了什么,因为它引发了下一个错误
NotFoundError: Node was not found
http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js
Line 2
我怀疑 Dojo 还没有准备好,但也许我错了......是否可以使用 jQuery 来动态加载 Dojo?