日期:2014-05-16 浏览次数:20386 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title></title>
</head>
<body>
<div id="divContainer"></div>
[code=javascript]
<script type="text/javascript">
function UserPower(id, parentId, title, url)
{
this.Id = id;
this.ParentId = parentId;
this.Title = title;
this.URL = url;
}
function ParseDom(content)
{
var newObject = document.createElement("div");
newObject.innerHTML = content;
return newObject.childNodes[0];
};
function Test()
{
var data =
[
new UserPower(1, '', '目录1', ''),
new UserPower(11, '1', '页面11', 'page11.aspx'),
new UserPower(12, '1', ' 页面12', 'page12.aspx'),
new UserPower(2, '', '目录2', ''),
new UserPower(21, '2', '页面21', 'page21.aspx'),
new UserPower(22, '2', ' 页面22', 'page22.aspx'),
];
var rootNode = document.getElementById("divContainer");
GreateMenu(data, '', rootNode);
}
function GreateMenu(data, parentNodeId, parentNode)
{
for(i = 0; i < data.length; i++)
{
var id = data[i].Id;
var parentId = data[i].ParentId;
var title = data[i].Title;
var url = data[i].URL;
if(parentId == parentNodeId)
{
if(url.length == 0) //Directory
{
var newNode = ParseDom("<fieldset><legend>" + title + "</legend></fieldset>");
&nbs