2

我在设计 => 会话中有以下 div

<div class="widgettitle">
    <button type="button" class="close" data-dismiss="alert">×</button>
    <%= "<div class=\"flash_error\">#{h alert}</div>".html_safe unless alert.blank? %>
    <%= "<div class=\"flash_notice\">#{h notice}</div>".html_safe unless notice.blank? %>
  </div>

但是关闭按钮不起作用..任何人都可以帮忙...?

4

1 回答 1

2

嗨,你有合适的js吗?

假设您正在尝试使用 twitter bootstrap 的警报功能?

!function ($) {

  "use strict"; // jshint ;_;


 /* ALERT CLASS DEFINITION
  * ====================== */

  var dismiss = '[data-dismiss="alert"]'
    , Alert = function (el) {
        $(el).on('click', dismiss, this.close)
      }

  Alert.prototype.close = function (e) {
    var $this = $(this)
      , selector = $this.attr('data-target')
      , $parent

    if (!selector) {
      selector = $this.attr('href')
      selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
    }

    $parent = $(selector)

    e && e.preventDefault()

    $parent.length || ($parent = $this.hasClass('alert') ? $this : $this.parent())

    $parent.trigger(e = $.Event('close'))

    if (e.isDefaultPrevented()) return

    $parent.removeClass('in')

    function removeElement() {
      $parent
        .trigger('closed')
        .remove()
    }

    $.support.transition && $parent.hasClass('fade') ?
      $parent.on($.support.transition.end, removeElement) :
      removeElement()
  }


 /* ALERT PLUGIN DEFINITION
  * ======================= */

  var old = $.fn.alert

  $.fn.alert = function (option) {
    return this.each(function () {
      var $this = $(this)
        , data = $this.data('alert')
      if (!data) $this.data('alert', (data = new Alert(this)))
      if (typeof option == 'string') data[option].call($this)
    })
  }

  $.fn.alert.Constructor = Alert


 /* ALERT NO CONFLICT
  * ================= */

  $.fn.alert.noConflict = function () {
    $.fn.alert = old
    return this
  }


 /* ALERT DATA-API
  * ============== */

  $(document).on('click.alert.data-api', dismiss, Alert.prototype.close)

}(window.jQuery);

你是如何在你的应用程序中使用 twitter 引导程序的?

您是否包含//= require bootstrap在您的 application.js 文件中?这是我喜欢使用 gem bootstrap-sass 所必需的(依赖于 gem sass-rails)

于 2013-05-06T10:42:40.657 回答