Home >Web Front-end >JS Tutorial >Implementation method of displaying tree menu in javascript drop-down list_javascript skills
Very simple to use: click on the menu to display the following or not.
1. Main purpose: displays a menu item, then click it to hide it, click it again, and the following content will pop up
The two attributes overflow: hidden and overflow="visible" are used. In the clicked function, the setting attributes should be
node.style.overflow="visible"; Of course, setting the height of tr is also very important, just so that other options can be hidden
2. Use the same technology and add a few more, but it is more troublesome to pass parameters. It is very common to use this to pass parameters
Realization effect:
<!DOCTYPE html> <html> <head> <title>list.html</title> <!--<link rel="stylesheet" type="text/css" href="./styles.css">--> <style type="text/css"> dl{ height:18px;/*优先级问题,必须要写*/ overflow:hidden; } dd{ margin:0px; padding:0px; } .close{ height:18px;/*优先级问题,必须要写*/ overflow:hidden; } .open{ height:80px; overflow:visible; background-color:#ff8000; } </style> <script type="text/javascript"> function click2(node1){ // alert("aa"+node.nodeName);// td var nodes=node1.parentNode; // alert(nodes.nodeName); // alert("aa"+nodes.className); //※※通过传进的对象 判断采用哪种css模式 if(nodes.className=="open"){ nodes.className="close"; }else{ nodes.className="open"; } } </script> </head> <body> <!--层次列表--> <!--当很多时候采用传参就很麻烦,每个都需要去传参 <dl> <dt onclick="click1(0)">菜单条1</dt> <dd>菜单1</dd> <dd>菜单2</dd> <dd>菜单3</dd> <dd>菜单4</dd> </dl> <dl> <dt onclick="click1(1)">菜单条2</dt> <dd>菜单11</dd> <dd>菜单22</dd> <dd>菜单33</dd> <dd>菜单44</dd> </dl> <dl> <dt onclick="click1(2)">菜单条3</dt> <dd>菜单12</dd> <dd>菜单23</dd> <dd>菜单34</dd> <dd>菜单45</dd> </dl> --> <br/> <br/> <hr/> <!--<dl class="close">先手动采用css测试,可以然后采用编程使用--> <dl> <dt onclick="click2(this)">1菜单条1</dt> <dd>菜单1</dd> <dd>菜单2</dd> <dd>菜单3</dd> <dd>菜单4</dd> </dl> <dl> <dt onclick="click2(this)">2菜单条2</dt> <dd>菜单11</dd> <dd>菜单22</dd> <dd>菜单33</dd> <dd>菜单44</dd> </dl> <dl> <dt onclick="click2(this)">3菜单条3</dt> <dd>菜单12</dd> <dd>菜单23</dd> <dd>菜单34</dd> <dd>菜单45</dd> </dl> </body> </html>
After click: set background color (css setting)
How to use javascript to create a tree-shaped menu in a drop-down list. I believe you will have a general idea through this article. I also believe that the effect of the tree-shaped menu displayed in the drop-down list created by you is more exquisite than what I did.