母版页导航栏选中解决方案

html代码:

<div id="nav_content">
           <ul>
               <li id="default"><a href="default.html">首页</a></li>
               <li><a href="saleCar.html">我要卖车</a></li>
               <li><a href="buyCar.aspx">我要买车</a></li>
               <li><a href="storeFront.aspx">直营网点</a></li>
               <li id="test"><a href="login.aspx">会员专区</a></li>
               <li><a href="intro.aspx">走近安美途</a></li>
               <li><a href="recruit.aspx">人员招聘</a></li>
               <li><a href="contact.aspx">联系我们</a></li>
           </ul>
       </div>

 

js代码:

<script type="text/javascript">
            var ah = document.getElementById('nav_content').getElementsByTagName('a');
                    for (i = 0; i < ah.length; i++) {
                        if (window.location.href.indexOf(ah[i]) >= 0) {
                            ah[i].parentNode.className = "selected";
                        }

                    }

                    if (window.location.href.indexOf("DetailInfo.aspx") >= 0 || window.location.href.indexOf("CompareProducts.aspx") >= 0 || window.location.href.indexOf("buyCarFlow.aspx") >= 0 || window.location.href.indexOf("replace.aspx") >= 0) {
                        ah[2].parentNode.className = "selected";
                    }
    </script>

posted @ 2012-09-21 11:37  Uoolo  阅读(465)  评论(0编辑  收藏  举报