【问题标题】:Popover from the click of the content loaded via ajax单击通过 ajax 加载的内容的弹出窗口
【发布时间】:2013-05-21 18:58:30
【问题描述】:

我有密码

jQuery('a[rel=popover]').popover({
  html: true,
  title: '',
  content: function() {
    .....
    .....
  }
}).live('click', function(e) {
  e.preventDefault();
  ......
  ......
});

我有链接

<a rel="popover" href="#">link</a>

我的问题是单击加载页面时加载的链接可以正常工作。但是当通过ajax加载链接时,弹出框不起作用。

【问题讨论】:

  • 你使用的jquery版本是什么?
  • 使用事件委托...
  • 我使用jquery 1.8版本。

标签: jquery ajax twitter-bootstrap popover


【解决方案1】:

确保在 ajax 回调函数(成功)之后为动态添加的元素再次调用 popover.. 而不是 live() 使用 on() 委托事件

jQuery.ajax({
    url:.....
    ...
    success:function(data){
        //codes to appene a
       jQuery('a[rel=popover]').popover({
               html: true,
               title: '',
               content: function() {
               .....
               .....
               }
       }); 
    } 
});

jQuery(document).on('click','a[rel=popover]', function(e) {
  e.preventDefault();
  ......
  ......
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-27
    • 2011-03-23
    • 1970-01-01
    • 2013-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多