Twitter Bootstrap .popover() 函数在 Rails 中不起作用 [英] Twitter Bootstrap .popover() function not working in Rails

查看:36
本文介绍了Twitter Bootstrap .popover() 函数在 Rails 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试开始使用 Twitter Bootstrap for Rails.popover() 函数根本不起作用.没发生什么事.

I am trying to start using Twitter Bootstrap for Rails. The popover() function is not working at all. Nothing happens.

layouts/application.html.erb:

 <!DOCTYPE html>
 <html>
 <head>
 <%= stylesheet_link_tag    "application" %>
 <%= javascript_include_tag "http://twitter.github.com/bootstrap/1.4.0/bootstrap-buttons.js"       %>
 <%= javascript_include_tag "http://twitter.github.com/bootstrap/1.4.0/bootstrap-twipsy.js" %>
 <%= javascript_include_tag "http://twitter.github.com/bootstrap/1.4.0/bootstrap-popover.js" %>
 <%= csrf_meta_tags %>
 <script>
 $(function () {
     $("a[rel=popover]")
     .popover({
        offset: 10
     })
     .click(function(e) { 
            e.preventDefault()
     })
  });
 </script> 
 </head>
 <body>
 <%= yield %>
 </body>
 </html>

这是我的views/test/test.htlm.erb的一部分:

<li>
    <a data-placement="below" 
       class="btn danger span2" 
       data-content="This is a test" 
       href="#"        
       rel="popover">+ Test</a>
</li>

我的 Gemfile 的一部分:

Part of my Gemfile:

gem 'rails', '3.1.3'
gem 'jruby-openssl'
gem 'json'
 group :assets do
    gem 'sass-rails',   '~> 3.1.5'
    gem 'coffee-rails', '~> 3.1.1'
    gem 'uglifier', '>= 1.0.3'
    gem 'jquery-rails'
 end

我还尝试在我的 application.js 文件中复制/粘贴 twipsy.jspopover.js 并调用它我的布局/application.html.erb:

I also tried to copy/paste the twipsy.js and popover.js in my application.js file and to call it in my layouts/application.html.erb with:

<%= javascript_include_tag    "application" %>

我错过了什么?有什么想法吗?

What am I missing? Any ideas?

推荐答案

问题在于您使用的选择器:

The issue is with your selector you're using:

$("a[rel=popover]")

该 jQuery 选择器匹配整个 rel 属性,并根据 Bootstrap bug report,Rails 向 rel 标签添加了额外的属性,比如 nofollow.

That jQuery selector matches the entire rel attribute, and according to a Bootstrap bug report, Rails adds additional attributes to the rel tag, like nofollow.

尝试改用这个选择器:

$("a[rel*=popover]")

这篇关于Twitter Bootstrap .popover() 函数在 Rails 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆