JavaScript導航腳本判斷當前導航
更新時間:2016年07月12日 16:30:04 作者:zhaoyingyatou
這篇文章主要介紹了JavaScript導航腳本判斷當前導航的相關資料,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
廢話不多說,直接給大家貼代碼了。
<script> $(function () { //highlight current / active link 左側導航判斷當前活動導航 $('ul.main-menu li a').each(function () { var wo = window.location.href.substring(window.location.href.lastIndexOf('/') + 1, window.location.href.lastIndexOf('.')); if ($(this).attr('href') == (wo + ".html")) { $(this).parent().addClass('active'); $(this).parents().addClass('active'); $(this).parents('li').find("i:first").toggleClass("glyphicon-minus"); $(this).parents('ul').slideDown(); }else if (("dxs" == wo || "syd" == wo)&&($(this).attr('href')=="dbs.html")) { $(this).parent().addClass('active'); $(this).parents().addClass('active'); $(this).parents('li').find("i:first").toggleClass("glyphicon-minus"); $(this).parents('ul').slideDown(); } }); /*** begin 主頁左側菜單 */ $(".main-menu a").click(function () { //將當前l(fā)i設置為活動狀態(tài) $(this).find("i:first").toggleClass("glyphicon-minus"); }); $(".main-menu a").click(function () { //更換其他導航的加減號圖標 $(this).parent('li').siblings(".active").find("i:first").toggleClass("glyphicon-minus"); //alert($(this).index()); //去掉其他導航的點擊樣式并折疊 $(this).parent('li').siblings(".active").removeClass("active").children("ul").slideUp('fast'); $(this).next('ul').slideToggle('fast'); $(this).parent('li').addClass('active'); }); /************** end 主頁左側菜單 */ }) </script>
以上所述是小編給大家介紹的JavaScript導航腳本判斷當前導航,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!
相關文章
詳解JavaScript基于面向對象之創(chuàng)建對象(2)
這篇文章主要介紹了JavaScript基于面向對象之創(chuàng)建對象,詳細的分析面向對象的原型方式以及其他綜合的方式,感興趣的小伙伴們可以參考一下2015-12-12Javascript封裝id、class與元素選擇器方法示例
這篇文章主要給大家介紹了Javascript封裝id、class與元素選擇器的方法,文中給出了詳細的示例代碼,對大家的理解和學習具有一定的參考價值,需要的朋友們下面來一起看看吧。2017-03-03寫出更好的JavaScript程序之undefined篇(中)
前一篇我介紹了幾種廣為使用的利用undefined這個概念值的辦法,這一篇我會介紹一些不太常見的辦法,其中還包括一個很巧妙的,我個人覺得很值得推廣的辦法。2009-11-11