我已經嘗試過很多當前鏈接被激活的例子,但是沒有一個適用於我。我有一些鏈接,每個鏈接點擊時會加載內容。 我想要的是點擊鏈接後,即使在內容刷新後,風格仍然存在。 這是我的index.html當前鏈接不能正常工作
<form name="searchForm" method="post" action="index.html">
<div id="sorting">
<ul>
<li href="#" class="sort">Sort By</li>
<li class="sort-by-doc by">
<a href="#" id="1" onclick="setSorting(this.id)" th:text="#{sort.doc}"></a>
<div class="arrow-down"></div>
</li>
<li class="sort-by-date by">
<a href="#" id="2" onclick="setSorting(this.id)" th:text="#{sort.date}"></a>
<div class="arrow-down"></div>
</li>
<li class="sort-by-po by">
<a href="#" id="3" onclick="setSorting(this.id)" th:text="#{sort.po}"></a>
<div class="arrow-down"></div>
</li>
</ul>
</div>
<input type="hidden" name="sortBy" th:value="${sortBy}"></input>
</form>
我已經添加了這個腳本
$('#sorting li').click(function() {
$('li.current').removeClass('current');
$(this).addClass('current');
});
有什麼事,我錯過了?
是,在'( 'li.current')錯過'$'removeClass( '當前');' – Tushar
之前,請檢查你的Javascript控制檯錯誤。發佈到SO。 – Barmar
對不起,我在這裏錯過了'$',但實際上在我的代碼中有'$'。這是行不通的。 –