Javascript 引导模式:无法调用方法';滚动顶部';未定义的

Javascript 引导模式:无法调用方法';滚动顶部';未定义的,javascript,jquery,ruby,twitter-bootstrap,capybara,Javascript,Jquery,Ruby,Twitter Bootstrap,Capybara,我不明白为什么会出现以下错误: 无法调用未定义的方法“scrollTop” 当我单击显示模态的链接时 我在唱jquery1.11,bootstrap3.1.1 关于代码(HAML) 显示模式的按钮: 。忘记密码。向右拉 =链接到t('.forget_password'),'#forget_password',数据:{target:“#forget_password”,切换:“modal”},tabindex:5 模态: #forgot_password.modal{tabindex: -1, r

我不明白为什么会出现以下错误: 无法调用未定义的方法“scrollTop”

当我单击显示模态的链接时

我在唱jquery1.11,bootstrap3.1.1

关于代码(HAML)

显示模式的按钮:

。忘记密码。向右拉
=链接到t('.forget_password'),'#forget_password',数据:{target:“#forget_password”,切换:“modal”},tabindex:5

模态:

#forgot_password.modal{tabindex: -1, role: 'dialog', "aria-labelledby" => t('.title'), "aria-hidden" => true}
  .modal-dialog
    .modal-content
      .modal-header
        %button.close{"aria-hidden" => "true", "data-dismiss" => "modal", :type => "button"} ×
        %h4= t('.title')
      .modal-body
        .form_wrapper
          .innertxt= t('.explanation')
          .forgot_password_form
            = form_for :forgot_password, url: forgot_password_path do |f|
              = text_field_tag :email, '', placeholder: t('email'), size: 50, autofocus: true
              = submit_tag t('send'), :class => 'btn'
问题发生的引导:(methodModal.prototype.show

显示错误:

TypeError: 'undefined' is not an object (evaluating 'that.$element
               .show()
               .scrollTop')
我猜
that.element
是null或未定义的,它破坏了代码。但我正在寻找修复/解决方案,因为它违反了我的测试规范!(红宝石与水豚)

我遵循了上面的示例,到目前为止,我看不出他们的代码和我的代码有任何区别。我尝试使用javascript而不是html来打开模式,但完全一样

有什么想法吗

编辑:Ruby/capybara代码

click_link 'Glemt adgangskode?'# Forgotten password?
  sleep 3
  within_frame('form_login') do
    fill_in 'email', with: 'jens@example.com'
    click_button 'Send'
  end

Edit2:顺便说一句,一切正常,模式弹出窗口正确,我只是得到了一个javascript错误,实际上并不影响使用。但我想理解并解决这个问题。

好吧,那是我的错误

实际上,我在几周前重写了jQuery.show()方法,但忘记了。。。返回一个
语句。这就是为什么scrollTop实际上是基于一个
未定义的
元素

$(function(){
  /**
   * Override hide function.
   */
  // Store a reference to the original remove method.
  var originalShowMethod = $.fn.show;

  $.fn.show = function(){
    var self = $(this);

    // Remove CSS classes that hide the element.
    self.removeClass('hidden hide invisible');

    // Apply the original method.
    return originalShowMethod.apply(this, arguments);
  }
});
现在效果更好了!重写允许我在调用show()函数时自动删除CSS类,以避免每次重复相同的内容! 对不起

$(function(){
  /**
   * Override hide function.
   */
  // Store a reference to the original remove method.
  var originalShowMethod = $.fn.show;

  $.fn.show = function(){
    var self = $(this);

    // Remove CSS classes that hide the element.
    self.removeClass('hidden hide invisible');

    // Apply the original method.
    return originalShowMethod.apply(this, arguments);
  }
});