javascript - Bootstrap 悬停图像显示示例

标签 javascript jquery css ajax twitter-bootstrap

我试图在用户将鼠标悬停在链接上时显示一个简单的图像,我正在关注 example found here字面意思,但我没有显示任何图像。

我有以下 UI,当用户单击查看车队时,数据会异步返回,示例代码放在返回数据的脚本中,因此:

enter image description here

用户点击查看车队

enter image description here

代码

$('a[rel=popover]').popover({
  html: true,
  trigger: 'hover',
  placement: 'bottom',
  content: function(){return '<img src="'+$(this).data('img') + '" />';}
});

ViewFleet.php

<td> <a class="btn" rel="popover" data-img="//placehold.it/400x200"> <?php echo $row['model']  ?></a></td>

非常感谢对上述内容的任何帮助或建议。

最佳答案

此代码有效:

  • 添加 bootstrap 和 jquery
  • 添加 http: 在图像 url 的开头,以防你 没有服务器测试(只需在浏览器中打开文件)没有http请求
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<a class="btn" rel="popover" data-img="https://placehold.it/400x200"> ABC TEST </a>
<script src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>


<script>
$('a[rel=popover]').popover({
html: true,
trigger: 'hover',
placement: 'bottom',
content: function(){return '<img src="'+$(this).data('img') + '" />';}
});
</script>

关于javascript - Bootstrap 悬停图像显示示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39672037/

相关文章:

javascript - PHP 和 AJAX 不工作

jquery - 在哪里添加动画属性 - jQuery CSS?

css - 如何使下拉内容在溢出时向右流动

html - float 菜单打扰了我的 float 内容

javascript - 使用 Javascript(不是 CSS!)在悬停时同时替换多个 <li> 文本

php - 快速加载网页

javascript - 现代浏览器不支持"DOMAttrModified"事件?

javascript - 在 JSViews 中访问/设置名称中带有点的观察者属性

jQuery UI 对话框 + Ajax 在 IE 6-7-8 上失败

html - 知道是什么导致悬停时图像顶部的轻微移动吗?