技术文章
当前位置:首页 > 技术文章

js特效,table无限级树形菜单

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>无限级树形菜单</title>
<style>
#A1 td { vertical-align: top; }
#A1 td.bj { font-family: Wingdings; color: #FF9933; text-align: center; }
#A1 td.bj , #A1 td.kg { width: 24; }
#A1 a:link , #A1 a: visited { color: #cc0080; text-decoration: none; }
#A1 a:hover { color: #0ff080; text-decoration: none; }
</style>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script language="JavaScript">
function treeClass(id)
{
this.id = id;
this.HTMLdata = "";
this.start = function() //菜单开始
{
this.HTMLdata += '<table border="0" cellpadding="0" cellspacing="0" width="100%" id="'+this.id+'">';
}
this.end = function() //菜单结束
{
this.HTMLdata += '</table>';
}
this.m_start = function(name,tt) //菜单组开始
{
this.HTMLdata += '<tr><td class="bj">'+(tt==1?'1':'0')+'</td>';
this.HTMLdata += '<td><a href="#" onclick="zgmm()">'+name+'</a></td>';
this.HTMLdata += '</tr>';
this.HTMLdata += '<tr style="display: '+(tt==1?'block':'none')+';">';
this.HTMLdata += '<td class="bj"> </td>';
this.HTMLdata += '<td>';
this.HTMLdata += '<table border="0" cellpadding="0" cellspacing="0">';
}
this.m_end = function() //菜单组结束
{
this.HTMLdata += '</table></td></tr>';
}
this.add_Sub = function(name,url,kj) //添加菜单项
{
this.HTMLdata += '<tr><td class="bj">2</td><td>';
this.HTMLdata += '<a target="'+kj+'" href="'+url+'">'+name+'</a>';
this.HTMLdata += '</td></tr>';
}
this.print = function() //输出菜单
{
document.write(this.HTMLdata);
}
}
function zgmm()
{
var ero = event.srcElement.parentElement.previousSibling;
var mo = event.srcElement.parentElement.parentElement.nextSibling;
mo.style.display = (mo.style.display=="none")?"block":"none";
ero.innerHTML = (mo.style.display=="none")?"0":"1";
}
</script>
</head>
<body>
<script language="JavaScript">
// 说明:
// 菜单组开始,m_start(name,tt); name为菜单组名称,tt为1菜单组初始时展开,为0不展开
// 菜单组结束:m_end();
// 添加菜单项:add_Sub("菜单项名称","url地址","框架名");
var tObj = new treeClass("A1")
tObj.start();
tObj.m_start("菜单组名称",1);
tObj.m_start("菜单组名称",0);
tObj.add_Sub("菜单项名称","#","_blank");
tObj.m_start("菜单组名称",0);
tObj.m_start("菜单组名称",0);
tObj.add_Sub("菜单项名称,这项不了","#","_blank");
tObj.add_Sub("菜单项名称","#","_blank");
tObj.m_end();
tObj.m_start("菜单组名称",0);
tObj.add_Sub("菜单项名称","#","_blank");
tObj.m_end();
tObj.m_end();
tObj.add_Sub("菜单项名称","#","_blank");
tObj.add_Sub("菜单项名称","#","_blank");
tObj.m_end();
tObj.m_start("菜单组名称",0);
tObj.add_Sub("菜单项名称","#","_blank");
tObj.add_Sub("菜单项名称","#","_blank");
tObj.m_end();
tObj.add_Sub("菜单项名称","#","_blank");
tObj.add_Sub("菜单项名称","#","_blank");
tObj.add_Sub("菜单项名称","#","_blank");
tObj.m_end();
tObj.m_start("菜单组名称",0);
tObj.add_Sub("菜单项名称","#","_blank");
tObj.add_Sub("菜单项名称","#","_blank");
tObj.add_Sub("菜单项名称","#","_blank");
tObj.m_end();
tObj.add_Sub("菜单项名称","#","_blank");
tObj.add_Sub("菜单项名称","#","_blank");
tObj.m_start("菜单组名称",0);
tObj.add_Sub("菜单项名称","#","_blank");
tObj.add_Sub("菜单项名称","#","_blank");
tObj.m_start("菜单组名称",0);
tObj.add_Sub("菜单项名称","#","_blank");
tObj.m_end();
tObj.m_end();
tObj.add_Sub("菜单项名称","#","_blank");
tObj.add_Sub("菜单项名称","#","_blank");
tObj.end();
tObj.print();
</script>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<style>
<!--
#iewrap{
position:relative;
height:30px
}
#iewrap2{
position:absolute
}
#dropmenu03{
filter:revealTrans(Duration=1.5,Transition=12)
visibility:hide
}
-->
</style>

</HEAD>
<BODY>
<ilayer id="dropmenu01" height=35px>
<layer id="dropmenu02" visibility=show>
<span id="iewrap">
<span id="iewrap2" onClick="dropit2();event.cancelBubble=true;return false">
<font face="宋体"><a href="#">点击这里进入↓</a></font>
</span>
</span>
</layer>
</ilayer>
<SCRIPT language=javascript><!--
var enableeffect=true
//修改以下为你自己的信息
var selection=new Array()
selection[0]='<font face="宋体"><a href="http://suhoo.51.net/">网络教室1</a></font><br>'
selection[1]='<font face="宋体"><a href="http://suhoo.51.net/">网络教室2</a></font><br>'
selection[2]='<font face="宋体"><a href="http://suhoo.51.net/">网络教室3</a></font><br>'
selection[3]='<font face="宋体"><a href="http://suhoo.51.net/">网络教室4</a></font><br>'
selection[4]='<font face="宋体"><a href="http://suhoo.51.net/">网络教室5</a></font><br>'
selection[5]='<font face="宋体"><a href="http://suhoo.51.net/">网络教室6</a></font><br>'
selection[6]='<font face="宋体"><a href="http://suhoo.51.net/">网络教室7</a></font><br>'
selection[7]='<font face="宋体"><a href="http://suhoo.51.net/">网络教室8</a></font>'
if (document.layers)
document.dropmenu01.document.dropmenu02.visibility='show'
function dropit2(){
if (document.all){
dropmenu03.style.left=document.body.scrollLeft+event.clientX-event.offsetX
dropmenu03.style.top=document.body.scrollTop+event.clientY-event.offsetY+18
if (dropmenu03.style.visibility=="hidden"){
if (enableeffect)
dropmenu03.filters.revealTrans.apply()
dropmenu03.style.visibility="visible"
if (enableeffect)
dropmenu03.filters.revealTrans.play()
}
else{
hidemenu()
}
}
}
function dropit(e){
if (document.dropmenu03.visibility=="hide")
document.dropmenu03.visibility="show"
else
document.dropmenu03.visibility="hide"
document.dropmenu03.left=e.pageX-e.layerX
document.dropmenu03.top=e.pageY-e.layerY+19
return false
}
function hidemenu(){
if (enableeffect)
dropmenu03.filters.revealTrans.stop()
dropmenu03.style.visibility="hidden"
}
function hidemenu2(){
document.dropmenu03.visibility="hide"
}
if (document.layers){
document.dropmenu01.document.dropmenu02.captureEvents(Event.CLICK)
document.dropmenu01.document.dropmenu02.onclick=dropit
}
else if (document.all)
document.body.onclick=hidemenu

//-->

</SCRIPT>
<!-- 通过下面的属性设置菜单出现的绝对位置和外观风格-->
<div id="dropmenu03" style="position:absolute;left:0;top:0;layer-background-color:white;background-color:white;width:80;visibility:hidden;border:0px solid black;padding:0px">
<script language="JavaScript1.2">
if (document.all)
dropmenu03.style.padding='6px'
for (i=0;i<selection.length;i++)
document.write(selection[i])
</script>
</div>
<script language="JavaScript1.2">
if (document.layers){
document.dropmenu03.captureEvents(Event.CLICK)
document.dropmenu03.onclick=hidemenu2
}
</script>
</BODY>
</HTML>