修改了一下數據格式
<!DOCTYPE html PUBLIC "
<html xmlns="
<head>
<meta http
<script type="text/javascript" src="
<title>JS無級樹樹形菜單
<style type="text/css">
{
margin
}
{
padding
}
{
overflow: hidden;
display: none;
height: auto;
}
{
display: block;
height:
line
padding
margin:
cursor: pointer;
border
}
{
background
color: #cf
}
{
color: #
text
}
{
color: #
}
{
height:
margin
border
}
</style>
</head>
<body>
<div class="btn">
<input name="" type="button" id="btn_open" value="全部展開" />
<input name="" type="button" id="btn_close" value="全部收縮" />
</div>
<div id="menuTree" class="menuTree">
</div>
</body>
</html>
<script type="text/javascript">
var json = { "navnums": { "
/*遞歸實現獲取無級樹數據並生成DOM結構*/
var str = "";
var forTree = function (o) {
var urlstr = "";
var keys = new Array();
for (var key in o) {
keys
}
for (var j =
k = keys[j];
if (typeof o[k] == "object") {
urlstr = "<div><span>" + k + "</span><ul>";
} else {
urlstr = "<div><span>" + k + "=" + o[k] + "</span><ul>";
}
str += urlstr;
var kcn =
if (typeof o[k] == "object") {
for (var kc in o[k]) {
kcn++;
}
}
if (kcn >
forTree(o[k]);
}
str += "</ul></div>";
}
return str;
}
/*添加無級樹*/
document
/*樹形菜單*/
var menuTree = function () {
//給有子對象的元素加[+
$("#menuTree ul")
var ulContent = $(element)
var spanContent = $(element)
if (ulContent) {
$(element)
}
});
$("#menuTree")
var ul = $(this)
var spanStr = $(this)
var spanContent = spanStr
if (ul
if (ul
ul
$(this)
} else {
ul
$(this)
}
}
})
} ()
/*展開*/
$("#btn_open")
$("#menuTree ul")
curzt("
})
/*收縮*/
$("#btn_close")
$("#menuTree ul")
curzt("+");
})
function curzt(v) {
$("#menuTree span")
var ul = $(this)
var spanStr = $(this)
var spanContent = spanStr
if (ul
$(this)
}
});
}
</script>
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/20277.html