更新资料
如果您的弹出框的选择器是一致的,则可以使用
selectorpopover构造函数的属性。
var popOverSettings = { placement: 'bottom', container: 'body', html: true, selector: '[rel="popover"]', //Sepcify the selector here content: function () { return $('#popover-content').html(); }}$('body').popover(popOverSettings);其他方法:
- ( 标准方式 )再次将弹出框绑定到要插入的新项目。将popoversettings保存在一个外部变量中。
- 使用
Mutation Event
/Mutation Observer
标识是否在ul
或元素上插入了特定元素。
资源
var popOverSettings = { //Save the setting for later use as well placement: 'bottom', container: 'body', html: true, //content:" <div style='color:red'>This is your div content</div>" content: function () { return $('#popover-content').html(); }}$('ul').on('DOMNodeInserted', function () { //listed for new items inserted onto ul $(event.target).popover(popOverSettings);});$("button[rel=popover]").popover(popOverSettings);$('.pop-Add').click(function () { $('ul').append("<li > <a>project name 2 <button rel='popover'></button> </a> </li>");});但是不建议将DOMNodeInsertedEvent用于性能问题和支持。也已弃此方法。因此,最好的选择是保存设置并在使用新元素更新后绑定。
另一种推荐的方法是根据MDN 使用MutationObserver而不是MutationEvent,但是同样,某些浏览器中的支持还是未知的,并且性能令人担忧。
MutationObserver = window.MutationObserver || window.WebKitMutationObserver;// create an observer instancevar observer = new MutationObserver(function (mutations) { mutations.forEach(function (mutation) { $(mutation.addedNodes).popover(popOverSettings); });});// configuration of the observer:var config = { attributes: true, childList: true, characterdata: true};// pass in the target node, as well as the observer optionsobserver.observe($('ul')[0], config);


