【问题标题】:Twitter Bootstrap .popover() function not working in RailsTwitter Bootstrap .popover() 函数在 Rails 中不起作用
【发布时间】:2012-01-29 09:37:27
【问题描述】:

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

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 的一部分:

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

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

<%= javascript_include_tag    "application" %>

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

【问题讨论】:

  • 您的页面是否也包含 jQuery?

标签: javascript ruby-on-rails twitter-bootstrap


【解决方案1】:

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

$("a[rel=popover]")

jQuery 选择器匹配整个rel 属性,并且根据Bootstrap bug report,Rails 将附加属性添加到rel 标记,如nofollow

尝试使用此选择器:

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

【讨论】:

  • 您好 Jared,感谢您的回复。实际上 $("a[rel=popover]") 可以很好地与 Rails 一起使用。我的 jquery 库链接有误。我将其替换为
猜你喜欢
  • 2023-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-16
  • 2015-10-17
  • 1970-01-01
  • 2014-12-28
相关资源
最近更新 更多