简体   繁体   English

带有动态内容的Twitter Bootstrap Popover

[英]Twitter Bootstrap Popover with dynamic content

I am trying to get Bootstrap popovers to work on dynamic content. 我正在尝试使Bootstrap弹出窗口在动态内容上工作。 I have a jQuery AJAX request that returns some rows of data. 我有一个jQuery AJAX请求,它返回一些数据行。 The AJAX success function will loop through and generate HTML code from the retrieved data. AJAX成功函数将循环遍历并根据检索到的数据生成HTML代码。 The generated HTML has the Bootstrap code in it but it doesn't work. 生成的HTML中包含Bootstrap代码,但是它不起作用。 If I just write the HTML code normally, it works fine. 如果我只是正常编写HTML代码,它就可以正常工作。

This is an example of what I'm trying to do. 这是我正在尝试做的一个例子。 newRowReg just loops through each record retrieved and appends it to the HTML string. newRowReg只是循环遍历每个检索到的记录,并将其附加到HTML字符串。

newRowReg += "<tr>";
newRowReg += "<td>" + xStatus + "</td>";
newRowReg += "<td><img src='green dotx.jpg' class='ppt1' data-container='body' data-toggle='popover' data-placement='right' data-content='Vivamus sagittis lacus vel augue laoreet rutrum faucibus.'>";
newRowReg += "</tr>";
$("#regTbl").append(newRowReg);

The Javascript code for the popup. 弹出窗口的Javascript代码。

$('.ppt1').popover({
    title: 'Title 1',
    trigger: 'hover',
    content: 'Some Content!'
  });

How do I get this to work when it's generated dynamically like this? 当它像这样动态生成时,如何使它起作用?

Lets have a link like this 让我们有这样的链接

<a href="#" id="show_media" class="btn btn-small btn-info" 
                            rel="popover" 
                            value="{{ $value->id }}"
                            data-content="<div id='div{{ $value->id }}'></div><script>loadMedia({{ $value->id }})</script>" 
                            data-original-title="My Title">Show Media</a>

Then before the body ends 然后在身体结束之前

  <script>  
    $(function (){ 
        $("#show_media").popover({placement: 'top', html: true});
    }); 
    function loadMedia(adsId){
        console.log("Ads ID: " +adsId);
        $('div#div' + adsId).html('xxxx');
    } 
    </script> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM