求助递归方法的解决?? 我用递归方法写出一个树状结构,不过是嵌套一层。比如说:中国 广东省 湖南省 安徽省下面,我想要的结果是:中国 广东省 广州市 茂名市 ……我该怎么写???如果说用纯JS又该怎么去写???我的e-mail地址:[email protected] 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你是想怎么做...存在数据库里读还是放到XML里读?或者有更好的办法? 楼主要JS的么?超级简单,比JAVA写得简单得多,呵呵。<html><head> <script type="text/javascript">function Tree(name, children) { this.name = name || ""; this.children = children || []; this.appendChild = function(child) { this.children.push(child); } this.toString = function() { var result = ""; result += "<div>|- " + this.name + "</div>"; for (var i = 0; i < this.children.length; i++) result += "<div style='margin-left: 1em'>" + this.children[i] + "</div>"; return result; }}var tree = new Tree("中国");tree.appendChild(new Tree("广东省", [new Tree("广州市"), new Tree("茂名市")]));</script></head> <body onload="document.getElementById('tree').innerHTML = tree"><div id="tree"></div> </body></html> 锁定JFrame的焦点 JAVA通过SOCKET接收二进制数据的困惑(用了三种方法都有不同问题),请教各位大虾 <Java数据库系统开发实例导>电子书! 谢谢 散分啦 散分啦 很简单的小问题 Port到byte的转换,捆扰我几天的问题了? 怎样获得数据库名字例表 ActionListener和ItemListener的问题 关于在计算器上放置按纽的问题! NoClassDefFoundError!!!第一次碰上 BBS版块列表跳转问题? javasript如何设置这样的焦点?? 关于正则表达式的问题
<html>
<head>
<script type="text/javascript">function Tree(name, children) {
this.name = name || "";
this.children = children || []; this.appendChild = function(child) {
this.children.push(child);
} this.toString = function() {
var result = "";
result += "<div>|- " + this.name + "</div>";
for (var i = 0; i < this.children.length; i++)
result += "<div style='margin-left: 1em'>" + this.children[i] + "</div>";
return result;
}
}var tree = new Tree("中国");
tree.appendChild(new Tree("广东省", [new Tree("广州市"), new Tree("茂名市")]));
</script>
</head>
<body onload="document.getElementById('tree').innerHTML = tree">
<div id="tree"></div>
</body>
</html>