【问题标题】:Twitter Bootstrap popovers not working in a Wordpress loopTwitter Bootstrap 弹出框在 Wordpress 循环中不起作用
【发布时间】:2013-01-04 05:54:24
【问题描述】:

我一直试图让引导弹出框在 Wordpress 循环中工作,但没有成功,这就是我到目前为止所做的:

<?php while($have_posts()): $the_post();
  $excerpt = strip_tags(get_the_excerpt());?>

  <a class="<?php echo the_ID()?>" href="<?php echo the_permalink();?>"><?php echo the_title();?></a>

  <script>
  jQuery('.<?php echo the_ID()?>').mouseenter(function(){
    jQuery(this).popover({
      html: true,
      title: '<?php echo the_title();?>',
      trigger: 'manual',
      placement:'top',
      content:'<?php echo $excerpt;?>'
    }).popover('show');
  });
  </script>
<?php endwhile;?>

这打印出我的期望

<a class="5598" href="http://mysite.oom/post/">Post Title</a>

<script>
jQuery('.5598').mouseenter(function(){
  jQuery('.5598').popover({
    html: true,
    title: 'Post Title',
    trigger: 'manual',
    placement:'top',
    content:'Post Excerpt'
  }).popover('show');
});
</script>

etc...

但是,悬停时弹出框没有显示,并且我没有收到任何脚本错误,所以我不知道为什么弹出框不起作用,我确实有 jQuery、bootstrap.js 和 bootstrap。 css 包含在页面加载中。任何帮助将不胜感激!

谢谢

【问题讨论】:

  • 脚本的哪一部分不起作用?在控制台中调用它们。
  • 嘿安德烈,我不确定哪个部分不起作用,因为我没有收到任何控制台错误。我已经在控制台中调用了每个帖子,并得到了预期的内容,每个帖子的 ID、标题和摘录。

标签: php html wordpress twitter-bootstrap


【解决方案1】:

以数字开头的类和 ID 不起作用!

众所周知,当您将班级作为数字进行时:

<div class="1234">...</div>

它不起作用。在你的情况下,它是这样的:

<script>
jQuery('.5598').mouseenter(function(){
  jQuery('.5598').popover({
    html: true,
    title: 'Post Title',
    trigger: 'manual',
    placement:'top',
    content:'Post Excerpt'
  }).popover('show');
});
</script>

类是一个纯数字。 5598。不工作。所以尝试用类似的东西替换它:

<a class="p5598" href="http://mysite.oom/post/">Post Title</a>

<script>
jQuery('.p5598').mouseenter(function(){
  jQuery('.p5598').popover({
    html: true,
    title: 'Post Title',
    trigger: 'manual',
    placement:'top',
    content:'Post Excerpt'
  }).popover('show');
});
</script>

我怀疑的另一件事是,.popover() 是一个函数,可以像实例化一样使用。所以,不要在.mouseenter() 下给出它。用这种方式替换整个脚本:

<script>
jQuery(document).ready(function(){
  jQuery('.p5598').popover({
    html: true,
    title: 'Post Title',
    trigger: 'manual',
    placement:'top',
    content:'Post Excerpt'
  })
  jQuery('.p5598').hover(function() {
    jQuery('.p5598').popover('show');
  }, function(){
    jQuery('.p5598').popover('hide');
  });
});
</script>

【讨论】:

  • 抽拳成功!非常感谢这有效,我不知道这一点。
  • 这样使用悬停有什么特别的原因吗?和触发器不是一回事吗:hover?
  • 我不确定...但是,.hover() 函数就是这样。
  • @dcd018 这个链接也可能有用what-characters-are-valid-in-css-class-names
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-04
  • 1970-01-01
相关资源
最近更新 更多