jQuery排序不能在嵌套链接上工作

jQuery Sortable not working on nested link

本文关键字:链接 工作 嵌套 排序 不能 jQuery      更新时间:2023-09-26

我使用Bootstrap选项卡并应用jQuery Sortable的拖动效果。到目前为止,它在包括Bootstrap选项卡的第一层工作得很好。但是当它到达嵌套层的第3层时,拖动效果就不能正常工作了

也是Bootstrap选项卡视图在第2和第3层,它的每个链接都没有加载相应的div视图(一个与。Tab -pane和引用id),但第一层工作得很好。我创建了每个链接的单击函数,以删除父'active'类,该类在单击时显示链接视图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%确定您想用代码完成什么。