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:我的錯誤,解決了。詳情請參閱我的回答。