簡體   English   中英

jQuery Sortable在嵌套鏈接上不起作用

[英]jQuery Sortable not working on nested link

我正在使用Bootstrap Tab並應用jQuery Sortable的Drag效果。 到目前為止,它在包括Bootstrap選項卡在內的第一級上都可以正常工作。 但是當它到達嵌套級別的3級時,拖動效果無法正常工作。

同樣在第二層和第三層的Bootstrap Tab視圖中,它的每個鏈接都沒有加載相應的div視圖(具有.tab-pane和引用ID的div視圖),但是第一層工作正常。 我為每個鏈接創建了一個單擊函數,以刪除父級“活動”類,該類在單擊時顯示鏈接視圖div,但似乎無濟於事。

var nestedList = $("ul.nested_with_switch li ul").children("li");

nestedList.click(function(){
    $(this).data('clicked', true);
})

nestedList.click(function(){
    if($(this).data('clicked') === true){
     nestedList.parents("ul li").removeClass("active");
     nestedList.find("li").removeClass("active");
    }
})

這是代碼

首先刪除似乎什么都不做的代碼...替換:

nestedList.click(function(){
    $(this).data('clicked', true);
})

nestedList.click(function(){
    if($(this).data('clicked') === true){
     nestedList.parents("ul li").removeClass("active");
     nestedList.find("li").removeClass("active");
    }
})

與:

nestedList.click(function(){
    nestedList.parents("li").removeClass("active");
    nestedList.find("li").removeClass("active");
})

接下來,您可能想使用.children("li")而不是.find("li") ,但是我不確定100%您要用代碼完成什么。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM