Dynamic implementation of multi-level menu on the left side of JavaScript

Source: Internet
Author: User

The implementation of the multi-level menu dynamics on the left side of js is very simple. It is just a matter of a few more levels. Well, now let's talk about my design ideas. First, add the following code from the first level:Copy to ClipboardReference: [www.bkjia.com] <div> <a onclick = "news_pro ('1. 1')"> 1 </a> </div>
<Div id = "1.1" type = "parmname" text = "parmname">
<Div> <a onclick = "news_pro ('1. 100')"> 1.1 </a> </div>
</Div> This shows two categories. Click the parent-Level Display (hide) sub-level menu, and the JS Code will also be in one sentence:Copy to ClipboardReference: [www.bkjia.com] function news_pro (o)
{
Var obj = document. getElementById (o)
Obj. style. display = ""? Obj. style. display = "none": obj. style. display = "";
}
Is it a little too simple? Yes, it's that simple, but it's not over yet. Let's continue to look down; then add Level 3 and Level 4 sub-menus:Copy to ClipboardReference: [www.bkjia.com] <div> <a onclick = "news_pro ('1. 1')"> 1 </a> </div>
<Div id = "1.1" type = "parmname" text = "parmname">
<Div> <a onclick = "news_pro ('1. 100')"> 1.1 </a> </div>
<Div id = "1.1.1">
<Div> <A onclick = "news_pro ('1. 1.1.1 ')"> 1.1.1 </a> </div>
<Div id = "1.1.1.1">
<Div> 1.1.1.1 </div>
<Div> 1.1.1.2 </div>
</Div>
<Div> 1.1.2 </div>
</Div>
& Lt; div & gt; 1.2 & lt;/div & gt;
& Lt; div & gt; 1.3 & lt;/div & gt;
</Div>
The js Code still only has that line. so easy, but is it true? The answer is NONONO! When you click a level, the page jumps. This is what we want, but the menu on the left is changed to the original one, and the status I just clicked is not saved, what should we do? Because my colleague is using ASP, it seems that there is no view status, so do I use session to save it? It seems to work, but if you click a little faster, you will find that the menu is sometimes different several times, but the response is not enough or the session is lost. In the end, unfortunately, I found my name very interesting, level 1 is 1, level 2 is 1.1 Level 3 is 1.1.1, Level 4 is 1.1.1.1. What do you think? I think of a multi-level category query for database design !? It seems that the category in discuz is designed in this way. It also queries quickly, so I will give it a fast, just so happy.

The Code is as follows:Copy to ClipboardReference: [www.bkjia.com] <div> <a onclick = "news_pro ('1. 1')" href = "? Id = 1.1 "> 1 </a> </div>
& Lt; div id = "1.1" & lt; % If InStr (request. querystring ("id"), "1.1") = 0 Then response. write style = 'display: none; '%>
<Div> <a onclick = "news_pro ('1. 1.1 ')" href = "? Id = 1.1.1 "> 1.1 </a> </div>
<Div id = "1.1.1" style = "display: none;" <% If InStr (request. querystring ("id"), "1.1.1") = 0 Then response. write style = 'display: none; '%>
<Div> <A onclick = "news_pro ('1. 1.1.1 ')" href = "? Id = 1.1.1.1 "> 1.1.1 </a> </div>
<Div id = "1.1.1.1" <% If InStr (request. querystring ("id"), "1.1.1.1") = 0 Then response. write style = 'display: none; '%>
<Div> 1.1.1.1 </div>
<Div> 1.1.1.2 </div>
</Div>
<Div> 1.1.2 </div>
</Div>
& Lt; div & gt; 1.2 & lt;/div & gt;
& Lt; div & gt; 1.3 & lt;/div & gt;
</Div>
<Div> <a> 2 </a> </div>
<Div> <a> 3 </a> </div>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.