dijit.byId 返回未定义

发布于 2024-11-01 13:57:27 字数 1984 浏览 2 评论 0原文

很奇怪,我在 dojo.addOnLoad(function{...}) 中调用 dijit.byId() ,它返回未定义。为了检查id是否存在,我同时调用dojo.byId(),它返回一些对象。所以我猜这个组件不是 dijit 组件?这是整个代码:请帮助我,谢谢您的建议!

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>

<!-- Dojo/Diji definations -->
<link href='../dojoroot/dijit/themes/tundra/tundra.css' type='text/css' rel='stylesheet'/>
<link href='../dojoroot/dojo/resources/dojo.css' type='text/css' rel='stylesheet'/>

<script type="text/javascript" src="../dojoroot/dojo/dojo.js" djConfig="parseOnLoad: true"></script>


<!-- Main scripts -->

<script type="text/javascript">
    dojo.addOnLoad(function()
    {
        // Include library
        dojo.require("dijit.layout.BorderContainer");
        dojo.require("dijit.layout.TabContainer");
        dojo.require("dijit.layout.ContentPane");

        // add the select child event to the tab panel
        alert(dijit.byId("contentTabPanel"));  // return no defined
        alert(dojo.byId("contentTabPanel")); // return an object

    });
</script>
</head>

<body class="tundra">
<div dojoType="dijit.layout.BorderContainer" style="width: 100%; height: 100%;">
    <!-- Content Tab Panel -->
    <div id="contentTabPanel" dojoType="dijit.layout.TabContainer" region="center">
        <!-- Tab UserGroup -->
        <div dojoType="dijit.layout.ContentPane" title="UserGroup">
        </div>
    </div>
</div>
</body>
</html>

天哪!!!!我知道原因了!!!!我花了 5 个小时来解决这个愚蠢的错误:

我必须在

    // Include library
    dojo.require("dijit.layout.BorderContainer");
    dojo.require("dijit.layout.TabContainer");
    dojo.require("dijit.layout.ContentPane");

dojo.addOnLoad(function() { !!!

It's very strange, I call dijit.byId() in dojo.addOnLoad(function{...}), it return undefined. In order to check if the id exist, i call dojo.byId() at the same time, it return some object. So I guess the component is not a dijit component? this is the whole code: Please help me, thanks in advice!

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>

<!-- Dojo/Diji definations -->
<link href='../dojoroot/dijit/themes/tundra/tundra.css' type='text/css' rel='stylesheet'/>
<link href='../dojoroot/dojo/resources/dojo.css' type='text/css' rel='stylesheet'/>

<script type="text/javascript" src="../dojoroot/dojo/dojo.js" djConfig="parseOnLoad: true"></script>


<!-- Main scripts -->

<script type="text/javascript">
    dojo.addOnLoad(function()
    {
        // Include library
        dojo.require("dijit.layout.BorderContainer");
        dojo.require("dijit.layout.TabContainer");
        dojo.require("dijit.layout.ContentPane");

        // add the select child event to the tab panel
        alert(dijit.byId("contentTabPanel"));  // return no defined
        alert(dojo.byId("contentTabPanel")); // return an object

    });
</script>
</head>

<body class="tundra">
<div dojoType="dijit.layout.BorderContainer" style="width: 100%; height: 100%;">
    <!-- Content Tab Panel -->
    <div id="contentTabPanel" dojoType="dijit.layout.TabContainer" region="center">
        <!-- Tab UserGroup -->
        <div dojoType="dijit.layout.ContentPane" title="UserGroup">
        </div>
    </div>
</div>
</body>
</html>

OMFG!!!!! I know the reason!!!!! I cost 5 Hours just for this STUPID error:

I MUST write the

    // Include library
    dojo.require("dijit.layout.BorderContainer");
    dojo.require("dijit.layout.TabContainer");
    dojo.require("dijit.layout.ContentPane");

outside the dojo.addOnLoad(function() { !!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文