javascript - 在 Bootstrap Popover 中插入图像

标签 javascript jquery twitter-bootstrap bootstrap-popover

我正在使用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 上看到过一些示例,但它对我来说不起作用,因为我想将其插入按钮声明中。

最佳答案

利用弹出窗口函数的content设置:

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

<强> DEMO

关于javascript - 在 Bootstrap Popover 中插入图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23629282/

相关文章:

javascript - 如何使用 FormData API 发出 POST 请求

javascript - 是否可以捕获 jstree 上下文菜单项的点击?

javascript - 使用来自 Javascript 变量的消息更新 facebook 状态

javascript - 使用 jquery 重置 html 元素

html - 在同一 Rails 应用程序中使用两个独立的 CSS 框架

html - 目标第一个 Div 图像 CSS

javascript - 如何在JS中将从PHP页面获取的数据传递到服务器本地页面?

jquery - Django 管理自定义 javascript 加载顺序

jquery - 如何使用 jQuery 将 <tbody> 添加到指定的 <table>?

jquery - 带有 tabindex ="-1"的模态将焦点放在选项卡上