我可以在Bootstrap popover中使用动态内容吗?

Ste*_*ner 16 javascript php jquery popover twitter-bootstrap

我在"重复区域"中使用Bootstrap Popover来显示推荐书.每个推荐都有一个"查看属性详细信息"按钮,可以打开弹出窗口.在Pop中我希望显示与每个推荐和图像细节相关联的图像.图像路径存储在数据库的一列中,以便显示我需要将图像源绑定到内容的每个推荐的图像,但它不接受PHP.我使用的脚本允许我将html写入内容,但需要动态创建图像.动态文本适用于'a'标记'标题'选项,但不适用于内容.

任何人都可以阐明这一点吗?

这就是我所拥有的.

<script type="text/javascript">
 $(document).ready(function() {
  $("[rel=details]").popover({
  placement : 'bottom', //placement of the popover. also can use top, bottom, left or     right
  html: 'true', //needed to show html of course
  content : '<div id="popOverBox"><img src="<?php echo $row_rsTstmnlResults['image']; ?>"        width="251" height="201" /></div>' //this is the content of the html box. add the image here or anything you want really.
});
});
</script>
    <a href="#" rel="details" class="btn btn-small pull-right" data-toggle="popover"     title="<?php echo $row_rsTstmnlResults['property_name']; ?>" data-content="">View Property</a>
Run Code Online (Sandbox Code Playgroud)

kat*_*ras 17

var popover = $("[rel=details]").popover({
    trigger: 'hover',
    placement: 'bottom',
    html: 'true'
}).on('show.bs.popover', function () {
    //I saw an answer here  with 'show.bs.modal' it is wrong, this is the correct, 
    //also you can use   'shown.bs.popover to take actions AFTER the popover shown in screen.
    $.ajax({
        url: 'data.php',
        success: function (html) {
            popover.attr('data-content', html);
        }
    });
});
Run Code Online (Sandbox Code Playgroud)


Oth*_*ali 7

一岁:(但这可能会帮助另一个人

删除你的 js 脚本并添加这个:

var content = $('[id*="yourDivId"]');
var title = "Your title, you can use a selector...";

$('[data-toggle="popover"]').popover({
    html: true,
    content: function () {
        return content.html();
    },
    title: function() {
      return title.html();
    }
});
Run Code Online (Sandbox Code Playgroud)


Mur*_*san 4

这是通用方法,但使用 ASP.Net 处理程序来处理图像。在PHP中使用类似的东西动态生成图像

<script type="text/javascript">
 $(document).ready(function() {
  $("[rel=details]").popover({
  placement : 'bottom', //placement of the popover. also can use top, bottom, left or     right
  html: 'true', //needed to show html of course
  content : getPopoverContent(this)// hope this should be link
});
});

function getPopoverContent(this)
{
 return '<div id="popOverBox"><img src="/getImage.php?id="'+this.data("image-id")+' 
 width="251" height="201" /></div>'
}
</script>

<a href="#" rel="details" class="btn btn-small pull-right" 
data-toggle="popover"     data-image-id="5" data-content="">View Property</a>
Run Code Online (Sandbox Code Playgroud)