Javascript twitter引导动态添加下拉列表
我正在实施一个用户通知系统。加载页面时,会发出AJAX请求,如果存在通知,则会将其呈现为一个隐藏的Javascript twitter引导动态添加下拉列表,javascript,twitter-bootstrap,drop-down-menu,Javascript,Twitter Bootstrap,Drop Down Menu,我正在实施一个用户通知系统。加载页面时,会发出AJAX请求,如果存在通知,则会将其呈现为一个隐藏的,但如果单击通知项,则会显示该页面 我在我的页面上有几个带引导功能的下拉列表,所以这不是问题所在 元素的加载和创建工作正常。如果我检查Firebug,它们会出现在DOM中 // this is in the top bar <a id="notifications" href="/user/profile/notifications" data-toggle="notifications-al
,但如果单击通知项,则会显示该页面
我在我的页面上有几个带引导功能的下拉列表,所以这不是问题所在
元素的加载和创建工作正常。如果我检查Firebug,它们会出现在DOM中
// this is in the top bar
<a id="notifications" href="/user/profile/notifications" data-toggle="notifications-alert">Benachrichtigungen</a>
// and this appended to the end of body
<ul id="notifications-alert" class="notifications dropdown-menu" style="display: none;">
<li class="event_new">[..]</li>
<li class="event_new">[..]</li>
</ul>
我也试过手动扳机,但还是没用
$notifications.addAttr('data.toggle', 'notifications-alert')
.click(function(e) { e.preventDefault(); $(this).dropdown('toggle'); })
.dropdown();
你知道为什么它不起作用吗
@编辑:我的错误,解决了。有关详细信息,请参见我的答案。中的所有示例都显示了链接[tag a]和下拉列表[tag ul]以及同一父级。也许简单的解决方案是,您应该在a之后添加ul,而不是在正文$(“a选择器”)的末尾添加ul。中的所有示例都显示了链接[tag a]和下拉[tag ul]以及同一父项。也许简单的解决方法是,您应该在a之后添加ul,而不是在正文$('a selector')的末尾添加ul。在(ul)
$notifications.addAttr('data.toggle', 'notifications-alert')
.click(function(e) { e.preventDefault(); $(this).dropdown('toggle'); })
.dropdown();