2

我正在使用Bootstrap Popver。我在弹出窗口中插入了一些数据,并且还想插入图像。这是我尝试过的。

代码:

var img = '<div id = "image"><img src = "http://news.bbcimg.co.uk/media/images/71832000/jpg/_71832498_71825880.jpg" /></div>';
var button = "<button title = " + obj.hostname + "&#44;&#32;" + gpu.toUpperCase() +
        " data-content = \"" + metric_name[metric] + ":&#32;" + display_val + img + "\"" +
        " data-id=\"" + detailed_summary + "\"" +
        " data-text = \"" + obj.hostname + ", " + gpu.toUpperCase() + ", " + metric_name[metric] + ":&#32;" + display_val + "\"" +
        " class=\"btn " + button_state + " gpu btn-lg open-InfoModal\"" +
        " data-toggle=\"modal\" " +
        " data-html=\"true\" " +
        " rel=\"popover\" " +
        " data-target=\"#hostInfo\" " +
        " href=\"#infoModal\"></button>";

初始化:

$('button').popover({
            trigger: "hover",
            placement: get_popover_placement,
            html: true
});

我在 Stack Overflow 上看到了一些示例,但它对我不起作用,因为我想将它插入到按钮声明中。

4

2 回答 2

3

利用contentpopover功能的设置:

$('button').popover({
            trigger: "hover",
            placement: get_popover_placement,
            html: true,
            content: img //loads the image inside the popover container
});

演示

于 2014-05-13T11:59:05.953 回答
2

我已经使用下面的代码解决了它。

   button = "<button title = " + obj.hostname + "&#44;&#32;" + gpu.toUpperCase() +
           " data-content = \"" + returnPOContent(metric_name[metric], display_val) + "\"" +
       //" data-content = \"" + metric_name[metric] + ":&#32;" + display_val + "\"" +
        " data-id=\"" + detailed_summary + "\"" +
        " data-text = \"" + obj.hostname + ", " + gpu.toUpperCase() + ", " + metric_name[metric] + ":&#32;" + display_val + "\"" +
        " class=\"btn " + button_state + " gpu btn-lg open-InfoModal\"" +
        " data-toggle=\"modal\" " +
        " data-html=\"true\" " +
        " rel=\"popover\" " +
        " data-target=\"#hostInfo\" " +
        " href=\"#infoModal\"></button>";

function returnPOContent(mName, dVal) {
    var popOverContent = mName + ": " +dVal+"</br><div id='test'><img src='http://news.bbcimg.co.uk/media/images/71832000/jpg/_71832498_71825880.jpg'/></div>"; 

    return popOverContent;
}

    $("button").popover({
            trigger: "hover",
            placement: get_popover_placement,
            html: true
      });
于 2014-05-13T13:26:22.753 回答