我在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>


但是,它在Uncaught TypeError: $(...).cropper is not a function处出现错误$("#teh").cropper();

最佳答案

我认为您正在使用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" />

关于javascript - 未捕获的TypeError:$(…).cropper不是函数-cropper.js,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59728272/

10-10 19:07