本文实例讲述了javascript动态生成树形菜单的方法。分享给大家供大家参考,具体如下:
Box_0_none = "../images/4_clos.gif" ;
treeview_Box_0_line = "../images/4_none.gif" ;
treeview_Box_2_open = "../images/2_open.gif" ;
treeview_Box_2_none = "../images/2_none.gif" ;
treeview_Box_2_close = "../images/2_clos.gif" ;
treeview_Box_1_open = "../images/3_open.gif" ;
treeview_Box_1_none = "../images/3_none.gif" ;
treeview_Box_1_close = "../images/3_clos.gif" ;
//===============================================
//Class : nodeitem
//status------------------------1:two-direction 0:noBox 0: disactivite
// 2:three-0direction 1:close-Box 1: activite
// 2:open-Box
//===============================================
function nodeitem( parentkey,key,lable,img ) {
this.lable = lable ;
this.key = key ;
this.parent = findNode( parentkey ) ;
if( this.parent != null ) {
aa = this.parent.status ;
if( aa.substring( 1,2 ) == "0" )
this.parent.status = aa.substring( 0,1 ) + "1" + aa.substring( 2,3 ) ;
if( this.parent.maxsubitem != null )
this.parent.maxsubitem.status = "2" + this.parent.maxsubitem.status.substring( 1,3 ) ;
this.parent.subitems[ this.parent.subitems.length ] = this ;
this.parent.maxsubitem = this ;
}
else {
if( tv_topnodeitem != null ) {
alert( "不能有两个顶项!" ) ;
return ;
}
tv_topnodeitem = this ;
}
this.img = img ;
this.tag = null ;
this.status = "100" ;
this.subitems = new Array() ;
this.maxsubitem = null ;
this.id = nodeitemRegister( this ) ;
//**********************
this.questionId = 0;
this.description = "";
//this.url = null;
//**********************
//added by msb for the sort and move up/down
/*if ( this == tv_topnodeitem )
{
this.nodeIndex = 0;
} else {
this.nodeIndex = this.parent.subitems.length;
}*/
//end added
}
//added by msb for the sort and move up/down
function nodeitem_moveUp() {
if (this == tv_topnodeitem) return; //topitem
ssubitems = this.parent.subitems;
for ( i=0; iIoUsitem = ssubitems[i]
}
prevIoUsitem.nodeIndex = this.nodeIndex;
this.nodeIndex = this.nodeIndex -1;
swap(this,prevIoUsitem);
*/
//label_on_click(this.id);
this.parent.refresh();
lable_on_click(this.id);
}//moveUp()
function nodeitem_moveDown() {
if (this == tv_topnodeitem) return; //topitem
ssubitems = this.parent.subitems;
for ( i=0; i