0

我是道场新手。我已尝试设置示例 Dojo 页面,但未加载 Dojo 组件。相反,我收到以下错误

ReferenceError: dojo 没有定义
dojo.require("dijit.form.Dialog");

但是应用了 CSS,class="dijitHidden" 隐藏了 DIV。

以下是我的 HTML:

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="dijit/themes/tundra/tundra.css" />
<link rel="stylesheet" type="text/css" href="dojox/grid/resources/Grid.css">
<link rel="stylesheet" type="text/css" href="dojox/grid/resources/tundraGrid.css">
<script language="text/javascript" src="dojo/dojo.js" ></script>
<script>
    dojoConfig = {
        isDebug: true,
        parseOnLoad: true,
        async: true
        //foo: "bar"
    };
</script>
<script>
    dojo.require("dojo.Dialog");
    function showDialog(){
        dijit.byId("terms").show();
    }
    function hideDialog(){
    dijit.byId("terms").hide();
    }
</script>
    <meta charset="utf-8"> 
    <title> Hello Dojo</title>
</head>
<body>
<h1> Welcome to Dojo</h1>
<div id="contentDiv">
    <button onclick="showDialog()" > view terms and conditions</button>
    <div class="dijitHidden">
        <div data-dojo-type="digit.Dialog" style="widht:600px" data-dojo-props="title:'terms and conditions'" id="terms">
            Digit Dialog Box Appears
            <button onclick="hideDialog();"> I Agree</button>
        </div>
    </div>
</div>
</body>
</html>
4

3 回答 3

0

也已经在评论中回答了,dojoConfig 定义得太晚了。此外,您需要使用要求:

require(["dijit/form/Dialog"], function (formDialog) {...});

于 2013-05-22T20:09:34.820 回答
0

我假设您使用的是 Dojo 1.6 或某些不支持 AMD 的版本。代码看起来不错,也许您需要将 language="text/javascript" 更改为 type="text/javascript" 或者您可以在下一行进行调试:

console.log(dojo);
alert("Wait");

并检查 dojo 是否正确加载。

如果现在没有任何效果,我还建议检查 CDN dojo 库版本。

<script src="//ajax.googleapis.com/ajax/libs/dojo/1.6.3/dojo/dojo.xd.js"></script>
于 2015-04-27T17:39:11.633 回答
0

dojoConfig 必须在渲染 dojo.js 文件之前出现。

您的编码风格显示 dojo <1.7。因此,请使用 djConfig 而不是 dojoConfig。

您在 data-dojo-type="dijit.Dialog" 处出错

于 2015-12-18T18:42:45.810 回答