L@_@K<html>
<head>
<title>Create Child Button</title>
</head>
<body>
    <div id="mydiv">
    <input id="btnRoot" type="button" value="Root" /><br />
    </div>
</body>
<script type="text/javascript">var oContainer = document.getElementById("mydiv");
var oRoot = document.getElementById("btnRoot");
oRoot.onclick = CreateChild;function CreateChild()
{
    var btnChild = document.createElement("input");
    btnChild.type = "button";
    btnChild.id = this.id + "_" + oContainer.getElementsByTagName("input").length;
    btnChild.value = btnChild.id;
    btnChild.onclick = CreateChild;    oContainer.appendChild(btnChild);
    oContainer.appendChild(document.createElement("br"));
}
</script>
</html>

解决方案 »

  1.   

    我明白了。
      我把事件写错了。
      不能写createchild()
      要写createchild。。
      javascript里面函数也是一个对象。
      谢谢兄弟。
      

  2.   

    hi。。用document.write()。。
      把html码写在指定的地方。。
      有没有什么办法????
      

  3.   

    <html>
    <head>
    <title>Create Child Button</title>
    </head>
    <body>
        <div id="divRoot">
            <input id="btnRoot" type="button" value="Root" style="cursor: hand;" /><br>
        </div>
    </body>
    <script type="text/javascript">var oRoot = document.getElementById("btnRoot");
    oRoot.container = null;
    oRoot.onclick = CreateChild;function CreateChild()
    {
        //alert(this.nextSibling.nodeName);
        if (this.container == null)
        {
            var divContainer = document.createElement("div");
            this.container = this.parentNode.insertBefore(divContainer, this.nextSibling);
            this.container.style.marginLeft  = "20px";
            this.container.style.border = "1px solid blue";
            if (this.container.nextSibling)
            {
                this.parentNode.removeChild(this.container.nextSibling);
            }
        }    var btnChild = document.createElement("input");
        btnChild.type = "button";
        btnChild.id = this.id + "_" + this.container.getElementsByTagName("input").length;
        btnChild.value = btnChild.id;
        btnChild.style.cursor = "hand";
        btnChild.onclick = CreateChild;    if (this.container.hasChildNodes())
        {
            this.container.appendChild(document.createElement("br"));
        }
        this.container.appendChild(btnChild);
    }
    </script>
    </html>
      

  4.   

    这个树的原形基本上已经写好了
      hahahahaha
      你要是在武汉
     我就请你吃饭
      把你QQ留下把???