我如何用dojo创建一个div? [英] How do i create a div with dojo create?

查看:117
本文介绍了我如何用dojo创建一个div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过dojo创建(包括h1和ul)从此示例生成divNodes0 div:

i want to generate the divNodes0 div from this example via dojo create (including the h1 and ul):

<body class="mobile">
    <div dojoType="dojox.mobile.View" id="mobileView">
        <div dojoType="dojox.mobile.ScrollableView" id="divNodes01" scrollDir="v" style="background-color: #d0d0d0;">
            <h1 dojoType="dojox.mobile.Heading" fixed="top" id="h1Nodes01"></h1>
            <ul id="ulNodes01" dojoType="dojox.mobile.RoundRectList"></ul>
        </div>
    </div>
[...]
</body>

我以这种方式尝试(没有成功):

i tried it this way (without sucess):

var mobileView = document.getElementById("mobileView");
dojo.create("div",{
            id: "divNodes0",
            dojoType: "dojox.mobile.ScrollableView",
            scrollDir: "v",
            style: "background-color: #d0d0d0"
            },
            mobileView,"first");


var mainNodeDiv = document.getElementById("divNodes0");
dojo.create("h1",{
            id: "h1Nodes0",
            dojoType: "dojox.mobile.Heading",
            back: "zurŸck",
            moveTo: "divNodes0",
            fixed: "top",
            label: "Knoten&uuml;bersicht"
            },
            mainNodeDiv,"first");

    dojo.create("ul",{
            id: "ulNodes0",
            dojoType: "dojox.mobile.RoundRectList"
            },
            mainNodeDiv);

请问Tom

推荐答案

如果要按ID查找节点,则通常要使用 dojo.byId('someId')

If you want to look up nodes by Id, you generally want to use dojo.byId('someId')

dojo.create 的第三个参数可以是domNode(像您正在使用)或dom节点的ID: dojo.create('h1',{},'divNodes0','first')

The third parameter to dojo.create can be either a domNode (like you are using) or an id of a dom node: dojo.create('h1',{},'divNodes0','first')

根据你的 dojoType 属性似乎是要使用widgets而不是dom节点。窗口小部件通常是具有内置样式和事件处理的domnode的模板,可轻松重复使用。实例化和放置小部件很简单:

Based on your usage of the dojoType attribute it seems like you want to use "widgets" rather than dom nodes. Widgets are generally a template of domnodes with built in styling and event handling that are easily reusable. Instantiating and placing widgets is simple:

var heading = new dojox.mobile.Heading({
  id: "h1Nodes0",
  dojoType: "dojox.mobile.Heading",
  back: "zurŸck",
  moveTo: "divNodes0",
  fixed: "top",
  label: "Knoten&uuml;bersicht"
});
heading.placeAt('divNodes0','first');

这篇关于我如何用dojo创建一个div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆