Uncaught TypeError: $(...).cropper is not a function - cropper.js

Uncaught TypeError: $(...).cropper is not a function - cropper.js

我试过这里的教程 link

我的密码是

<!DOCTYPE html>
<html>
<head>    
<link href="cropper.css" rel="stylesheet" />
</head>
<body>
<img id="teh" src="image.png" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="cropper.js"></script>
<script>        
    $("#teh").cropper();
</script>
</body>
</html>

但是,它在 $("#teh").cropper();

处遇到错误 Uncaught TypeError: $(...).cropper is not a function

已经找到解决方案。我需要添加

<script src="jquery-cropper.js"></script>

所以,就变成了

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="cropper.js"></script>
<script src="jquery-cropper.js"></script>

我认为您正在使用 jQuery 新版本,而它支持旧版本。

var image = document.getElementById('image');
var cropper = new Cropper(image, {
  aspectRatio: 16 / 9,
  crop: function(e) {
    console.log(e.detail.x);
    console.log(e.detail.y);
  }
});
<link href="https://cdnjs.cloudflare.com/ajax/libs/cropperjs/0.8.0/cropper.min.css" rel="stylesheet"/>
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/cropperjs/0.8.0/cropper.min.js"></script>

<img id="image" src="https://lh5.googleusercontent.com/-_nU33sjf1SI/AAAAAAAAAAI/AAAAAAAASgQ/VOkKnOIxP8g/photo.jpg?sz=328" />