繁体   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