【问题标题】:Jquery find(...).live is not a functionJquery find(...).live 不是一个函数
【发布时间】:2019-06-02 12:54:24
【问题描述】:

我最近将我的 jquery 库更新到 3.3.1,从那时起 jquery.fileupload-ui 在这里中断

 _initEventHandlers: function () {
        $.blueimp.fileupload.prototype._initEventHandlers.call(this);
        var filesList = this.element.find('.files'),
            eventData = { fileupload: this };
        filesList.find('.start a')
            .live(
                'click.' + this.options.namespace,
                eventData,
                this._startHandler
            );
        filesList.find('.cancel a')
            .live(
                'click.' + this.options.namespace,
                eventData,
                this._cancelHandler
            );
        filesList.find('.delete a')
            .live(
                'click.' + this.options.namespace,
                eventData,
                this._deleteHandler
            );
    },

我的感觉是 live 已被弃用。

如何修改此代码以解决此问题?

亲切的问候

【问题讨论】:

标签: jquery jquery-file-upload


【解决方案1】:

你的感觉是对的,live() 很久以前就被弃用了,已经被删除了。

现代方法是使用on() 方法的委托签名。给定您的代码,它看起来像这样:

_initEventHandlers: function() {
  $.blueimp.fileupload.prototype._initEventHandlers.call(this);
  var filesList = this.element.find('.files'),
    eventData = { fileupload: this },
    clickEventName = 'click.' + this.options.namespace;

  filesList.on(clickEventName, '.start a', eventData, this._startHandler);
  filesList.on(clickEventName, '.cancel a', eventData, this._cancelHandler);
  filesList.on(clickEventName, '.delete a', eventData, this._deleteHandler);
},

【讨论】:

    猜你喜欢
    • 2018-10-01
    • 2012-12-30
    • 2023-01-11
    • 2012-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多