IE8 - JQuery 中的 .on() 函数在 ie8 中不受支持

IE8 - .on() function in JQuery is not supported in ie8

您好,我正在使用 cropit 插件在我的项目中裁剪图像。但是它在 JQUERY 的 .on() 方法中显示了一些错误,而在 IE8 中 运行 this 。请帮助我解决这个问题。

这里是codepen

中的示例代码

错误显示在以下代码中

 this.$fileInput.on("change.cropit", this.onFileChange.bind(this));
        this.$preview.on(Cropit.PREVIEW_EVENTS, this.onPreviewEvent.bind(this));
        this.$zoomSlider.on(Cropit.ZOOM_INPUT_EVENTS, this.onZoomSliderChange.bind(this));
        if (this.options.allowDragNDrop) {
            this.$preview.on("dragover.cropit dragleave.cropit", this.onDragOver.bind(this));
            return this.$preview.on("drop.cropit", this.onDrop.bind(this));
        }

错误仅在 IE8 中显示。提前致谢

这在 IE8(真实版)中工作得很好

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script> 
<script>
$(document).ready(function () {
    this.$fileInput.on("change.cropit", this.onFileChange.bind(this));
        this.$preview.on(Cropit.PREVIEW_EVENTS, this.onPreviewEvent.bind(this));
        this.$zoomSlider.on(Cropit.ZOOM_INPUT_EVENTS, this.onZoomSliderChange.bind(this));
        if (this.options.allowDragNDrop) {
            this.$preview.on("dragover.cropit dragleave.cropit", this.onDragOver.bind(this));
            return this.$preview.on("drop.cropit", this.onDrop.bind(this));
        }
});
</script>

我用 IE 8 加载了一个 XP 盒子。CodePen 根本没有 运行,其他主要沙箱(如 JSFiddle 或 JSBin)也没有。因此,我从 CodePen(在工作箱中)获取代码并将其放入静态 HTML 文件中。接下来,我链接到 proper Cropit source file(不是 vendor.js,这可能取自他们的 PR 页面),遇到的第一个错误不是 jQuery,而是 Cropit 本身:

Object.defineProperty(exports, '__esModule', {
  value: true
});

Object doesn't support this property or method

经过进一步研究,IE8 对 defineProperty() 的支持有限。事实上,从这个 ECMA compatibility site 来看,IE8 与大多数 Object 属性斗争。

问题不在于您使用的 jQuery 版本,而是 IE8。您只需要像 Microsoft will.

那样停止对它的支持