javascript - Bootstrap 弹出窗口不起作用

标签 javascript jquery css twitter-bootstrap

我想在用户将鼠标悬停在 div 上时切换弹出窗口。是否可以将 popover 与 div 一起使用,或者我做错了什么。我的代码:

<div class="grid-item content-text" data-toogle ="popover" data-content="Lorem ipsum dolor sit amet" data-trigger="hover" id="intro">
    <h3> INTRO</h3>
    <p>Hover me</p>
</div>

我也在 $(document).ready() 函数中使用了这些:

  $(function () {
    $('[data-toggle="popover"]').popover();
  });

我的 js 脚本是有序的,我的 head 标签顶部有 bootstrap.css

<script type="text/javascript" src="js/jquery-1.12.3.min.js" ></script>  
<script type="text/javascript" src="js/bootstrap.min.js" ></script>
<script type="text/javascript" src="js/customScripts.js" ></script>

但是,我认为我的弹出窗口实现有问题。即使只有 data-trigger = "focus",我也失败了。我在 codepen.io 上创建了一支笔:http://codepen.io/ngp130895/pen/qZQJOJ

最佳答案

基本上它没有识别哪个 element - popover 被附加了,原因不明。但是,当我尝试提供 divclassname 时,它实际上识别了 element

$(function() {
  $('.grid-item').popover();
})

DEMO HERE

Note - I've also given width to div and specified data-placement attribute to place it properly. Since div width was 100% by default, it will move popover to end and hence will not be visible on the screen. You need to play around with these attributes. Also, I've not seen anywhere, popover is used on div. Please go through few of their properties and suggestions mentioned in their official site

关于javascript - Bootstrap 弹出窗口不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36996576/

相关文章:

namespaces - 共享 JavaScript 库的命名空间还是使用你自己的?

javascript - 测试固定电话号码模式的最快方法

javascript - mocha测试中以下js箭头函数中 `this`指向什么?

javascript - 添加加载动画,直到特定的 JavaScript 完成加载

html - 最大宽度不适用于 flexbox+align-items : center

css - 是否可以覆盖父元素的背景以显示祖父元素的背景?

javascript - 是否有一个 Javascript 事件可以根据用户输入不断更新 DOM?

javascript - Jquery 不返回表单 INPUT 中的值

javascript - 如果根/父元素向上/向下滚动则显示按钮,如果不是则隐藏该按钮

html - css链选择器