0
我有一個Bootstrap 3彈出窗口,用於顯示在表格單元格中單擊圖標的時間。表格行在頁面加載時動態插入。我的jQuery使用Ajax調用來獲取popover的內容。當顯示彈出窗口時,其標題由其內容爲空。設置Bootstrap彈出窗口的數據內容不起作用
下面是相關的HTML:
<td>1-Year Individual <a tabindex="0" class="history-info" data-trigger="focus" data-memberid="123" data-toggle="popover" data-placement="left" data-title="Membership history for Fred Smith" data-html="true" data-content=""><span class="glyphicon glyphicon-info-sign" style="color:grey;"></span></a></td>
正如你所看到的,數據內容屬性設置爲空。
這是我的javascript。
$("#member-table .history-info").on("show.bs.popover", function() {
var memberid=$(this).data("memberid");
$.ajax({
url: "memberships-GetHistoryInfo.php",
type: "GET",
data: {MemberID: memberid},
datatype: "html",
async: false,
success: function (data) {
$(this).data("content",data);
}
});
})
我已經與$(本)。數據( 「內容」,數據)後的警報權覈實;在數據內容被設置爲期望值的情況下,除了標題之外沒有任何內容顯示在彈出窗口中。
感謝您的建議,但不幸的是,它沒有區別。 – Pete
啊,我繼續用bootstrap文檔查看popovers,用jQuery在我的瀏覽器控制檯中抓取了元素,並用'attr()'改變了'data-content'屬性,點擊按鈕,內容變成了什麼我已經設置它 - 也許你必須在show.bs.popover'之前設置內容?從http://getbootstrap.com/javascript/#popovers上的'.popover('show')'方法文檔看起來,這就是它檢查內容的一點。相反,在頁面加載時,您是否可以通過ajax獲取所有彈出窗口的數據,並在結果上循環並將數據屬性添加到所有行中? – sauntimo
我在找到的鏈接中找不到jQuery popover示例,也許我錯過了它。我最初是在頁面加載時爲每個圖標創建數據內容,但由於表中的行數和需要的數據庫訪問,性能並不理想。我希望通過僅在單擊圖標時動態創建數據內容來提高性能。 – Pete