我有一個左側的導航,顯示/隱藏內容的權利。目前,當您點擊一個鏈接時,它將淡入右側的相應內容,並將活動的類添加到該鏈接。我的問題是,如果再次單擊活動鏈接,右側的內容會再次消失。我想在鏈接處於活動狀態時解除該點擊,並且如果您單擊另一個導航鏈接(隨後從上一個鏈接中刪除該類並將其添加到當前鏈接中),請將點擊事件重新綁定到所有不活動的鏈接。禁用/取消綁定點擊活動項目,重新綁定時點擊無效
這裏是我當前的代碼:
$('.mixesSidebar ul li').click(function() {
//Get the attribute id
var liId = $(this).attr('id');
//removeClass active from all li's, addClass active to this
$('.mixesSidebar ul li').removeClass('active');
$(this).addClass('active');
//Hide all content on the right
$('.mixesContent ul').hide();
//Find the content with the same class as the clicked li's ID, and fadeIn
$('.mixesContent').find('.' + liId).fadeIn('slow');
});
非常感謝您的幫助!