0

一切似乎都已加载(jquery、jcrop 和我的 avatar.js 文件)。我似乎无法弄清楚发生了什么。我的脚本按以下顺序加载:

<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery.Jcrop.js?body=1" type="text/javascript"></script>
<script src="/assets/gmaps4rails/gmaps4rails.base.js?body=1" type="text/javascript"></script>
<script src="/assets/gmaps4rails/gmaps4rails.googlemaps.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery-fileupload/vendor/jquery.ui.widget.js?body=1" type="text/javascript">         </script>
<script src="/assets/jquery-fileupload/jquery.iframe-transport.js?body=1" type="text/javascript">    </script>
<script src="/assets/jquery-fileupload/jquery.fileupload.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery-fileupload/basic.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery-fileupload/vendor/tmpl.js?body=1" type="text/javascript"></script>
<script src="/assets/avatars.js?body=1" type="text/javascript"></script>

avatars.js.coffee 包含以下内容:

jQuery ->
  new AvatarCropper()

class AvatarCropper
  constructor: ->
    $('#cropbox').Jcrop
      aspectRatio: 1
      setSelect: [0, 0, 600, 600]
      onSelect: @update
      onChange: @update

  update: (coords) =>
      $('#avatar_crop_x').val(coords.x)
      $('#avatar_crop_y').val(coords.y)
      $('#avatar_crop_w').val(coords.w)
      $('#avatar_crop_h').val(coords.h)
      @updatePreview(coords)

    updatePreview: (coords) =>
      $('#preview').css
        width: Math.round(100/coords.w * $('#cropbox').width()) + 'px'
        height: Math.round(100/coords.h * $('#cropbox').height()) + 'px'  
        marginLeft: '-' + Math.round(100/coords.w * coords.x) + 'px'
        marginTop: '-' + Math.round(100/coords.h * coords.y) + 'px'

在 javascript 控制台中,我得到:

Uncaught TypeError: Object [object Object] has no method 'Jcrop' 

任何帮助将不胜感激。

4

2 回答 2

2

问题是 jQuery.noConflict(); 调用另一个脚本...

于 2013-01-03T19:15:16.017 回答
1

我面临同样的问题。当我将 jquery 文件放在 jcrop.js 之前时,我的问题得到了解决。

于 2013-02-05T13:47:15.747 回答