简体   繁体   English

Popover中的级联下拉菜单

[英]Cascading Dropdowns within Popover

I have a problem with implementing dropdown menus within a popover. 我在弹出式窗口中实现下拉菜单时遇到问题。 I have looked at the bootstrap documentations and have tried everything from messing with the data toggle classes to try to get it to work, but nothing has happened. 我查看了引导程序文档,并尝试了所有操作,从弄乱数据切换类到使其正常工作,都没有发生。

In the first link, I have a cascading dropdown menu that works after clicking the link. 在第一个链接中,我有一个级联下拉菜单,单击该链接后即可使用。 LINK1 LINK1

But in this link, I tried to put the same content as the code in link1 into a popover, and it lost it's capability to cascade. 但是在此链接中,我试图将与link1中的代码相同的内容放入弹出窗口,但它失去了级联功能。 LINK2 LINK2

I have looked into how to solve this, either by implementing manual click handlers or using the dropdown toggle, but have had no luck. 我已经研究了如何通过实现手动单击处理程序或使用下拉开关来解决此问题,但是没有运气。 To be more specific, I am not sure if I need to apply the same classes to the other sub-dropdowns, as I do to this one: 更具体地说,我不确定是否需要像对这个子下拉列表一样将相同的类应用于其他子下拉列表:

<a href="#" class="dropdown-toggle" data-toggle="dropdown">
Click Here <span class="caret"></span></a>

Thank you in advance. 先感谢您。

The problem is that the popover will create a new div in the DOM with the popover content, so in you js you have assigned the click event to an element that is never used. 问题是弹出窗口将在DOM使用弹出窗口内容创建一个新的div,因此在您的js中,您已将click事件分配给了从未使用过的元素。 If you inspect the code you can see there are two "click here" anchor. 如果检查代码,则可以看到有两个“单击此处”锚点。 To solve your problem you have to assign the event click using a different form. 要解决您的问题,您必须使用其他表格来分配事件单击。 I create a new jsfiddle for you http://jsfiddle.net/nB4U6/1016/ To assign an event to element that will create in the future you have to use this form 我为您创建了一个新的jsfiddle http://jsfiddle.net/nB4U6/1016/要将事件分配给将来将要创建的元素,您必须使用此表单

$(staticAncestors).on(eventName, dynamicChild, function() {});

In your case I have changed this 你的情况我已经改变了

$(".dropdown-menu > li > a.trigger").on("click", function(e) {});

with this 有了这个

$('body').on("click",".dropdown-menu > li > a.trigger",function(e){});

The event will be bound to the body which already exists. 该事件将绑定到已经存在的主体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM