z-blog讓導(dǎo)航突出顯示當(dāng)前頁(yè)鏈接條目:
我們的大致思路是這樣的,首先用js給導(dǎo)航部分中當(dāng)前鏈接項(xiàng)加個(gè)區(qū)分的ID,如<li id=“current”>首頁(yè)</li>,然后再用CSS定義就完成了。
原先功能簡(jiǎn)單的代碼
<script type="text/javascript">$(document).ready(function(){$("#menu ul>li").each(function() { //我們假設(shè)導(dǎo)航部分的ID為menu,結(jié)構(gòu)是<div id="menu"><ul><li>... if ($(this).find("a").attr("href")==document.URL){ $(this).attr("id","current") //給當(dāng)前頁(yè)的<li>加上id="current",如<li id="current">首頁(yè)</li> }});});</script>
haphic將這一代碼做了完善,此代碼只支持 Z-Blog 模板.
haphic 完善后的代碼
<script type="text/javascript"> $("#menu ul>li").each(function() { if ($(this).find("a").attr("href").toLowerCase() !== str00.toLowerCase()){ if (document.URL.toLowerCase().indexOf($(this).find("a").attr("href").toLowerCase()) !== -1){ $(this).attr("id","current") } }else{ if ($(this).find("a").attr("href").toLowerCase() == document.URL.toLowerCase()){ $(this).attr("id","current") } } });</script>
#menu ul li#current { background-color:#fff; color:#0B1316;}
新聞熱點(diǎn)
疑難解答
圖片精選