我花了2個小時試圖創建沒有成功的活動菜單,所以我想我會尋求幫助。我有一個HTML菜單,一些JS &三網融合嘗試將活動類添加到菜單項
$(function() {
var pgurl = window.location.href.substr(window.location.href
.lastIndexOf("/") + 1);
$("#index li a").each(function() {
if ($(this).attr("href") == pgurl || $(this).attr("href") == '')
$(this).addClass("active");
})
});
.active { font-weight:bold;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id='index'>
<div class='container'>
<div class='top'>
<h1><a href='/' title='The Maths Project'>The Maths Project</a></h1>
</div>
<ul class='section active_section' id='section_2'>
<li><span id='section_title_2' class='section_title'><a href='#' id='section_link_2'>Against the odds.</a></span>
<ul>
<li id='exhibit_106' class='exhibit_title'><a href="../against-the-odds/introduction"> → Introduction</a>
</li>
<li id='exhibit_83' class='exhibit_title'><a href='../against-the-odds/deriving-functions'> → Deriving functions</a>
</li>
<li id='exhibit_83' class='exhibit_title'><a href='../against-the-odds/exploiting-odds'> → Exploiting odds</a>
</li>
</ul>
</li>
</ul>
<ul class='section' id='section_3'>
<li><span id='section_title_3' class='section_title'><a href='http://themathsproject.co.uk' id='section_link_3'>Remembering everything.</a></span>
<ul>
<li id='exhibit_104' class='exhibit_title'><a href='../against-the-odds/black-swans'>black swans</a>
</li>
<li id='exhibit_72' class='exhibit_title'><a href='../against-the-odds/in-here-it-is-yesterday'>in here it is yesterday </a>
</li>
</ul>
</li>
</ul>
</div>
</div>
當用戶在特定頁面上,「一」的鏈接,他們點擊了哪個應該成爲大膽。但是,無論出於何種原因,它都不起作用。
我將不勝感激任何幫助,
問候,
傑克
你有沒有試過,如果你發現 –
的簡介部分,當點擊你的'pgurl'變量將是商店'introduction'相似的價值觀,以提醒pgurl和HREF,但是你的'href'你在你的'每個檢查檢查時''循環將會是'../ against-odds/introduction'。只是思考的食物。 –