Implementation of Dynamic menu by jquery _ jquery

Source: Internet
Author: User
This article mainly introduces the sample code for jquery to implement a dynamic menu. For more information, see jquery. It is similar to the jquery pop-up window that uses JavaScript to operate css.

The procedure can be divided into the following steps:

• Create an html page containing the menu to be expressed

The Code is as follows:




Jquery Example 2: jquery menu







    I am menu 1
  • I am submenu 1

  • I am submenu 2



    I am menu 2
  • I am submenu 3

  • I am submenu 4






• Create a css file to control menu display

The Code is as follows:


/* To prevent all li nodes from displaying small dots, you can use the css Tag selector */
Li {
/* Remove the dot before the list */
List-style: none;
/* Indent effect */
Margin-left: 18px;
/* Hide the menu */
Display: none;
}
A {
/* Text display mode */
Text-decoration: none;
}


• Create a JavaScript file to control menu display

The Code is as follows:


/*
* Click the main menu. The sub-menu is displayed. Click the main menu again to hide the sub-menu.
* You need to write code so that the onclick event is added to the main menu during loading so that the submenu can be displayed when you click the main menu.
* Registration page Loading Method
*/
$ (Document). ready (function (){
// Var uls = $ ("ul ");
// Locate node a under ul
Var as =$ ("ul> ");
As. click (function (){
// First find the li in the current ul, and then display the li
// Obtain the clicked ul Node
Var aNode = $ (this );
// Find all the li nodes under the clicked ul Node
Var lis = aNode. nextAll ("li ");
// Display or hide ul's li subnodes
Lis. toggle ("slow ");
});
});

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.