Dhtmlxtree is a pretty good JavaScript tree control, which is used by the Web Background Management System to display functional menus or institutions, such as hierarchical and subordinate relationships, you can also customize icons and provide a wide range of APIs. For more information, see dhtmlxtree help documentation.
The effect is as follows:
By default, the dhtmlxtree tree control uses double-click mouse to expand the nodes to which it belongs. In fact, this is not in line with the usage habits of most people. It is better to expand and contract nodes by clicking, it is not difficult to implement this function. The key is to listen to the onclick event. The specific implementation is as follows:
Tree = New Dhtmlxtreeobject ( " Treeboxbox_tree " , " 100% " , " 100% " , 0 );
Tree. setimagepath ( " Tree/ " );
Tree. loadxmlstring (xmltree)
Tree. attachevent ( " Onclick " , Function (ID ){
VaR Hrefurl = Tree. getuserdata (ID, " URL " );
// Click expand and contract
// VaR Itemid = tree. getselecteditemid ();
VaR Itemid = ID;
If (Tree. haschildren (Itemid )){
If (Tree. getopenstate (Itemid) = " 1 " ){
Tree. closeitem (Itemid)
} Else {
Tree. openitem (Itemid)
}
}
});