This article describes the method of implementing a simple secondary navigation menu in JavaScript. Share it for your reference. The details are as follows:
<!DOCTYPE html PUBliC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:///TR/xhtml1/DTD/"> <html xmlns="http:///1999/xhtml" lang="zh-CN"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>cssMenu Demo</title> <style type="text/css"> <!-- *{margin:0;padding:0;border:0;} body { font-family: arial, Song style, serif; font-size:12px; } #nav { line-height: 24px; list-style-type: none; background:#666; } #nav a { display: block; width: 80px; text-align:center; } #nav a:link { color:#666; text-decoration:none; } #nav a:visited { color:#666;text-decoration:none; } #nav a:hover { color:#FFF;text-decoration:none;font-weight:bold; } #nav li { float: left; width: 80px; background:#CCC; } #nav li a:hover{ background:#999; } #nav li ul { line-height: 27px; list-style-type: none;text-align:left; left: -999em; width: 180px; position: absolute; } #nav li ul li{ float: left; width: 180px; background: #F6F6F6; } #nav li ul a{ display: block; width: 180px;width: 156px; text-align:left;padding-left:24px; } #nav li ul a:link { color:#666; text-decoration:none; } #nav li ul a:visited { color:#666;text-decoration:none; } #nav li ul a:hover { color:#F3F3F3;text-decoration:none;font-weight:normal; background:#C00; } #nav li:hover ul { left: auto; } #nav ul { left: auto; } #content { clear: left; } --> </style> <script type=text/javascript> <!--//--><![CDATA[//><!-- function menuFix() { var sfEls = ("nav").getElementsByTagName("li"); for (var i=0; i<; i++) { sfEls[i].onmouseover=function() { +=(>0? " ": "") + "sfhover"; } sfEls[i].onMouseDown=function() { +=(>0? " ": "") + "sfhover"; } sfEls[i].onMouseUp=function() { +=(>0? " ": "") + "sfhover"; } sfEls[i].onmouseout=function() { =(new RegExp("( ?|^)sfhover\b"), ""); } } } =menuFix; //--><!]]> </script> </head> <body> <ul > <li><a href="#">Product Introduction</a><ul> <li><a href="#">Product One</a></li><li><a href="#">Product One</a></li><li><a href="#">Product One</a></li><li><a href="#">Product One</a></li><li><a href="#">Product One</a></li><li><a href="#">Product One</a></li></ul> </li> <li><a href="#">Service introduction</a><ul> <li><a href="#">Service 2</a></li><li><a href="#">Service 2</a></li><li><a href="#">Service 2</a></li><li><a href="#">Service 2 Service 2</a></li><li><a href="#">Service 2Service 2Service 2</a></li><li><a href="#">Service 2</a></li></ul> </li> <li><a href="#">Successful Cases</a><ul> <li><a href="#">Case Three</a></li><li><a href="#">Case</a></li><li><a href="#">Case Three Case Three</a></li><li><a href="#">Case Three Case Three Case Three</a></li></ul> </li> <li><a href="#">About Us</a><ul> <li><a href="#">We Four</a></li><li><a href="#">We Four</a></li><li><a href="#">We Four</a></li><li><a href="#">We Four 111</a></li></ul> </li> <li><a href="#">Online Demo</a><ul> <li><a href="#">Demo</a></li><li><a href="#">Demo</a></li><li><a href="#">Demo</a></li><li><a href="#">Demo Demo</a></li><li><a href="#">Demo Demo</a></li><li><a href="#">Demo Demo</a></li><li><a href="#">Demo Demo</a></li><li><a href="#">Demo Demo Demo Demo Demo</a></li></ul> </li> <li><a href="#">Contact Us</a><ul> <li><a href="#">Contact Contact Contact Contact Contact Contact</a></li><li><a href="#">Contact and contact</a></li><li><a href="#">Contact</a></li><li><a href="#">Contact</a></li><li><a href="#">Contact</a></li><li><a href="#">Contact and contact</a></li><li><a href="#">Contact and contact</a></li></ul> </li> </ul> </body> </html>
I hope this article will be helpful to everyone's JavaScript programming.