javascript - 关闭 Bootstrap 警报

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

我正在使用 https://github.com/thoughtbot/paul_revere gem 用于管理我的 Rails 应用程序中的公告。这个 gem 有部分显示公告。它看起来像这样:

<% if announcement_visible?(current_announcement) %>
  <div id="announcement">
    <span><%= current_announcement.body.html_safe %></span>
    <span class="hide">
      <%= link_to "hide", "#", onclick: "hideAnnouncement('#{current_announcement.to_cookie_key}')" %>
    </span>
  </div>
<% end %>

我为它添加了一些 CSS:

#announcement{
  position: relative;
  left: 10px;
  width: 50%;

  @extend .alert;
  @extend .alert-dismissible;
  @extend .alert-info;
  @extend .animated;
  @extend .fadeInUp;
}

它看起来像这样: enter image description here

但我无法使隐藏链接以隐藏警报的功能起作用。而且我也想要 x 而不是 hide。有没有什么方法可以使用纯 css 而不覆盖 gem partial?

最佳答案

如果您无法在源代码或 gem 文件中更改它,请添加这个 jQuery 位好吗?

$(document).ready(function () {
  $("#announcement").find(".hide").html("&times;").attr("data-dismiss", "alert");
});

关于javascript - 关闭 Bootstrap 警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32090799/

相关文章:

ruby-on-rails - 如何使用 nginx 配置 phusion passenger 以支持 rails 中的 ssl?

javascript - Express JS 路由参数

javascript - 在 HTML 页面中查找元素时遇到问题

javascript - 叠加层可通过其前面的元素点击

html - 为什么跨度为 : auto and display: inline-block parent of svg is getting bigger height than its svg child?

javascript - 通过 ul li click 过滤和搜索 div 文本

javascript - 当元素溢出时如何增加元素的高度

asp.net - css、div 和 asp 的不透明度问题 :Image

ruby-on-rails - 遍历过去 7 天的日期

ruby-on-rails - RSpec 失败 : could not find table after migration. ..?