本文實例講述了js實現的四級左側網站分類菜單。分享給大家供大家參考。具體實現方法如下:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/> <script src="http://www.google-analytics.com/urchin.js" type="text/javascript"> </script> <script type="text/javascript"> _uacct = "UA-152060-1"; urchinTracker(); </script> <title>demo</title> <style type="text/css"> <!-- body { font-family: Arial, Helvetica, sans-serif; font-size: 11px; } #nav, #nav ul { list-style: none; background: #F9F9F9; font-weight: bold; padding: 0px; margin: 0px; border: solid 1px #CCCCCC; border-bottom: 0px; width: 150px; text-align: left; } #nav ul ul{ border: solid 1px #CCCCCC; border-bottom: 0px; } #nav a { display: block; width: 150px; width: 140px; color: #333333; text-decoration: none; text-align: center; border-bottom: solid 1px #CCCCCC; text-align: left; padding-left: 10px; } #nav a:hover{ color: #336666; } #nav a.selected{ background: url(/images/bb_expand.gif) no-repeat right 50%; } #nav li { line-height: 22px; position: relative; } #nav li ul { position: absolute; left: -999em; width: 150px; font-weight: normal; margin: 0px; padding: 0px; } #nav li li { width: 150px; } #nav li ul a { width: 150px; width: 126px; padding: 0px 12px; line-height: 22px; text-align: left; } #nav li ul ul { margin: 0px 0 0 150px; } #nav li:hover ul ul,#nav li.sfhover ul ul,#nav li:hover ul ul ul{ left: -999em; } #nav li:hover ul, #nav li li:hover ul,#nav li.sfhover ul, #nav li li.sfhover ul,#nav li li li:hover ul { left: auto; } #nav li:hover ul,#nav li.sfhover ul{ left: 150px; top: 0px; } #nav li:hover, #nav li.sfhover { background: #F5E3C0; } * html #nav li { float: left; height: 1%; } * html #nav li a { height: 1%; } --> </style> <script type="text/javascript"> <!--//--><![CDATA[//><!-- sfHover = function() { var sfEls = document.getElementById("nav").getElementsByTagName("LI"); for (var i=0; i<sfEls.length; i++) { sfEls[i].onmouseover=function() { this.className+=" sfhover"; } sfEls[i].onmouseout=function() { this.className=this.className.replace(new RegExp(" sfhoverb"),""); } } } if (window.attachEvent) window.attachEvent("onload", sfHover); //--><!]]> </script> </head> <body> <p><a href="javascript:history.back()">Back</a></p> <ul id="nav"> <li><a href="">Home</a></li> <li><a href="/aboutme.html">About Me</a></li> <li><a class="selected" href="/tutorials.html">Tutorials</a> <ul> <li><a href="#">Sub Menu 31</a></li> <li><a class="selected" href="#">Sub Menu 32</a> <ul> <li><a class="selected"href="#">Sub Menu 321</a><ul> <li><a href="#">Sub Menu 321</a></li> </ul></li> <li><a href="#">Sub Menu 322</a></li>