1
我正在实现用户通知系统。当页面被加载时,一个AJAX请求被做出,并且如果通知存在,它们被渲染成一个<ul>
,它被隐藏,但是如果通知项目被点击则应该出现。twitter bootstrap动态添加下拉框
我在我的页面上有几个带Bootstrap的工作下拉菜单,所以这不是问题。
元素的加载和创建工作正常。如果我使用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>
我还初始化下拉()当我追加设置data-toggle
属性。像这样:
$notifications.addAttr('data.toggle', 'notifications-alert')
.dropdown();
我也尝试过使用手动触发器,但仍然没有工作。
$notifications.addAttr('data.toggle', 'notifications-alert')
.click(function(e) { e.preventDefault(); $(this).dropdown('toggle'); })
.dropdown();
任何想法,为什么它不工作?
@EDIT:我的错误,解决了。详情请参阅我的回答。