<ul class="header-link"><li><a href="storeActive.html">到店活動</a></li><li><a href="fuwu.html">服務</a></li><li><a href="store.html">門店</a></li><li><a href="resource.html">資源</a></li></ul>
使用js判斷當前點擊的a標簽的 href屬性值是否和 地址欄的URL相同,相同就添加active類
$(".header-link>li>a").each(function(){var $this = $(this);var url = window.location.hrefif($this[0].href === String(url)){$(".header-link>li").removeClass("active");$this.parent().addClass("active");}});