[英]Bootstrap drop-down not working
I'm using the bootstrap drop-down in rails and it suddenly stopped working. 我在rails中使用bootstrap下拉菜单,但突然停止工作。 If I raise the click event on the link manually like $('a.dropdown-toggle').click()
it works fine, but if I actually click on it nothing happens. 如果我像$('a.dropdown-toggle').click()
这样手动引发链接上的click事件,它可以正常工作,但是如果我实际单击它,则不会发生任何事情。
If I attach a click handler using jQuery like $('a.dropdown-toggle').click(function(){alert('foo');})
then that fires when I click on the link. 如果我使用$('a.dropdown-toggle').click(function(){alert('foo');})
类的jQuery附加单击处理程序,则在单击链接时会触发该事件。
Is this because the event is being swallowed by something? 这是因为事件被某些东西吞没了吗? Is there any way to figure out what it is? 有什么办法弄清楚它是什么吗?
I can't reproduce the error in a jsFiddle-type environment, but here is the relevant html: 我无法在jsFiddle类型的环境中重现该错误,但以下是相关的html:
<li class="profile">
<div class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<i class="glyphicon glyphicon-user"></i>
Ben
</a>
<ul class="dropdown-menu pull-right" role="menu" aria-labelledby="User">
<li><a href="/users/edit.5399e28681f150251b000001"><i class="glyphicon glyphicon-edit"></i> Edit Account</a></li>
<li><a href="/users/sign_out" data-method="delete" rel="nofollow"><i class="glyphicon glyphicon-log-out"></i> Logout</a></li>
<li class="divider"></li>
<li role="presentation" class="dropdown-header">Admin</li>
<li><a href="/#providers"><i class="glyphicon glyphicon-plus"></i> Providers</a></li>
<li><a href="/admin/patients"><i class="glyphicon glyphicon-eye-open"></i> Patients</a></li>
<li><a href="/admin/users"><i class="glyphicon glyphicon-user"></i> Users</a></li>
<li><a href="/logs/index"><i class="glyphicon glyphicon-list-alt"></i> Logs</a></li>
</ul>
</div>
</li>
UPDATE: I've found that if I call $('a.dropdown-toggle').dropdown()
a few seconds after the page loads it works, but not if I call it right when the page loads. 更新:我发现,如果在页面加载后几秒钟调用$('a.dropdown-toggle').dropdown()
它会起作用,但是如果我在页面加载时正确调用它,那是$('a.dropdown-toggle').dropdown()
。 Also my accordions have a similar problem – they can drop down but they don't close back up unless you manually call the click event. 另外,我的手风琴也有类似的问题-它们可以下拉,但是除非您手动调用click事件,否则它们不会关闭。 So I'm guessing that right now it's due to something swallowing the click event, but I can't figure out what. 所以我猜现在是由于某些东西吞没了click事件,但我不知道是什么原因。
May be you should add dropdown
class to li
element 也许您应该将dropdown
类添加到li
元素
and remove <div class="dropdown">
并删除<div class="dropdown">
Hope to help:) 希望对您有所帮助:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.