栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在动态元素上绑定引导弹出窗口

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在动态元素上绑定引导弹出窗口

更新资料

如果您的弹出框的选择器是一致的,则可以使用

selector
popover构造函数的属性。

var popOverSettings = {    placement: 'bottom',    container: 'body',    html: true,    selector: '[rel="popover"]', //Sepcify the selector here    content: function () {        return $('#popover-content').html();    }}$('body').popover(popOverSettings);

其他方法:

  1. 标准方式 )再次将弹出框绑定到要插入的新项目。将popoversettings保存在一个外部变量中。
  2. 使用
    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);


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/400587.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号