第1、直接給當前頁面添加特殊樣式,當網頁刷新或者跳轉到下一頁後,樣式消失;函數
第2、狀況是即便刷新頁面後樣式仍然有效。直接上代碼。this
第一種狀況:對象
$(function(){
$('#profile-menu a').click(function(){
$('.current').removeClass('current');
$(this).addClass('current');
});
});rem
第二種狀況:文檔
$(function(){
$('#profile-menu a').each(function(){
if($(this)[0].href == String(window.location.href)){
$('.current').removeClass('current');
$(this).addClass('current');
}
});
});字符串