<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /><title>Untitled Document</title>
The first of these methods
<script type= "Text/javascript" >function change_bg (obj) {var A=document.getelementbyid ("menu"). getElementsByTagName ("a"); for (Var i=0;i<a.length;i++) {a[i].classname= ""; } obj.classname= "Current";} </script><style type= "Text/css" >body{font-size:17px; }.current{background:red; } #container ul{List-style-type:none;} #container ul li{Float:left; margin-right:3px;} #container ul Li A{text-decoration:none;color: #000;} </style><!--The second method of -<Scripttype= "Text/javascript"src= "Http://www.daixiaorui.com/Public/js/jquery.min.js"></Script><style>. Menu{padding:0;margin:0;List-style-type:None;}. Menu Li{background:#FFD1A4;Margin-right:1px;float: Left;Color:#fff; }. Menu Li a{Display:Block;width:80px;text-align:Center;Height:32px;Line-height:32px;Color:#fff;font-size:13px;text-decoration:None;}. Cur{background:#D96C00;Font-weight:Bold;}</style><ulclass= "Menu"ID= "Menu"> <Li><ahref= "demo.html">Home</a></Li> <Li><ahref= "te1.html">PHP synthesis</a></Li> <Li><ahref= "te2.html">Ecshop</a></Li></ul><Scripttype= "Text/javascript"> varUrlstr=Location.href; //get the address of the current page by Location.href in JS //Alert ((Urlstr + '/'). IndexOf ($ (this). attr (' href '))); varUrlstatus=false; $("#menu a"). each (function () { if((Urlstr+ '/'). IndexOf ($ ( This). attr ('href')) > -1&&$( This). attr ('href')!="') { $( This). addclass ('cur'); Urlstatus= true; } Else { $( This). Removeclass ('cur'); } }); if (!urlstatus) {$("#menu a"). EQ (0). addclass ('cur'); }</Script><!--Demo 1 (Static link effect): http://www.daixiaorui.com/Public/demo/js/navCur/demo.html Demo 2 (dynamic Link effect):/HTTP Www.daixiaorui.com/Public/demo/js/navCur/demo1.html?aa=1-
<!--A third method--
This method does not work when the href attribute of the A tag is not empty, and you must have the href attribute "javascript:void (0)" When adding the click method to the a tag.
$ ("#headMenu Li"). each (function (index) {
$ (this). Click (function () {
Console.log ($ ("#headMenu Li"));
$ ("#headMenu li"). Removeclass ("active");
Alert ("Cancel");
$ ("#headMenu li"). EQ (index). addclass ("active");
Alert ("Add");
});
// });
</ Body > </ HTML >
Use JS to realize the change of navigation switch effect (collect case)