jQuery“对象函数(e,t){return new v.fn.init(e,t,n)}没有方法”on“ [英] jQuery "Object function (e,t){return new v.fn.init(e,t,n)} has no method 'on'"

查看:2740
本文介绍了jQuery“对象函数(e,t){return new v.fn.init(e,t,n)}没有方法”on“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照 @coreyward 的示例将对象编辑表单放入Rails的模态对话框窗口中,这是此答案中列出的更新为rails 3.1在这个要点

I'm following @coreyward's example for putting object edit forms in modal dialog windows in Rails, which is outlined in this answer and updated for rails 3.1 in this gist.

我使用Rails 3.2.8和jQuery-Rails 2.1.3(jQuery 1.8.2是什么是加载在应用程序)。

I'm using Rails 3.2.8 and jQuery-Rails 2.1.3 (jQuery 1.8.2 is what's loading in the app). However, this coffeescript from the gist raises the error in the title, on line 7 (right after the comment).

$ ->
  $modal = $('#modal')
  $modal_close = $modal.find('.close')
  $modal_container = $('#modal-container')

  # Handle modal links with the data-remote attribute
  $.on 'ajax:success', 'a[data-remote]', (xhr, data, status) ->
    $modal
      .html(data)
      .prepend($modal_close)
      .css('top', $(window).scrollTop() + 40)
      .show()
    $modal_container.show();

  $.on 'click', '#modal .close', ->
    $modal_container.hide()
    $modal.hide()
    false


$ b b

此问题的评论让我这是一个jQuery版本问题可能是原因,这就是为什么我检查我的jQuery版本,但显然这个jQuery不像那个解决那个问题的老。我也验证了jQuery在这个脚本之前加载(或者至少,它在加载顺序中高于这个脚本)。

Comments on this question made me this a jQuery version issue might be the cause, which is why I checked my jQuery version, but obviously this jQuery isn't as old as the one which solved that problem. I've also verified that jQuery is loaded before this script (or at least, it's above this script in the load order).

我把coffeescript放在一个小提琴演示了问题(请参阅您的控制台的错误)。 (这也让我认为这不是一个问题,我的设置。)我会尝试不同的版本的jQuery,看看他们是否解决它,但也许代码是不可靠的?

I put the coffeescript above into a fiddle which demonstrates the problem (see your console for the error). (That also makes me think this isn't a problem with my setup.) I'll try different versions of jQuery to see if they resolve it, but maybe the code is just wonky? I don't know coffeescript well enough to see errors which might be obvious to others.

推荐答案

替换 $ .on 通过 $(document).on 删除错误... on 方法需要从一个DOM元素调用我可以告诉,从来没有看到它调用jQuery根对象之前...

Replacing $.on by $(document).on removes the errors ... The on method needs to be called on a DOM element from what I can tell, never saw it called on the jQuery root object before...

这篇关于jQuery“对象函数(e,t){return new v.fn.init(e,t,n)}没有方法”on“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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