jquery .bind() 是否已弃用?

Is jquery .bind() deprecated?

jquery bind() 是否已弃用或可以安全使用?

我在 SO 的评论和答案中看到很多关于 bind() 被弃用的评论,例如:Jquery Event : Detect changes to the html/text of a div

Is there a JavaScript/jQuery DOM change listener?

并且不知道使用它是否安全(不管它是好是坏)。

这里没有任何关于它被弃用的内容:https://api.jquery.com/bind/

我不认为它已被弃用,但 on 是附加事件的首选方法。

http://api.jquery.com/bind/

弃用意味着他们将来会删除它,但他们的文档似乎没有这么说。

编辑:

从 jQuery 3.0 开始,bind 已弃用。上面的 link 仍然相关,但已经更新。来自他们的文档:

As of jQuery 3.0, .bind() has been deprecated. It was superseded by the .on() method for attaching event handlers to a document since jQuery 1.7, so its use was already discouraged.

不,这不是 .on.bind 之间的区别,基本上 .bind 仅直接从元素即 $("#elem").bind(...) 调用,因此元素 [=调用绑定函数时,19=]必须存在。而 .on 在文档 i 上可以是 "bind"。 e. $(document).on("click",".class",funcion(){...});,所以如果你使用.append或其他方式动态添加元素,该事件将有效。

它在 jQuery 1.1 中没有弃用。如果您检查 .bind 事件的声明,您可以看到它只是调用 .on:

版本 jquery 1.11.3 实际上没有区别(除了用法)
bind: function( types, data, fn ) {
    return this.on( types, null, data, fn );
},

deprecated or it can be used safely?

正如其他人所说,不,它没有被弃用并且是安全的,它现在只是有点多余,只是为了向后兼容而存在。

虽然它似乎在

中被标记为已弃用
从 jQuery 1.12 和 2.2 开始,

.bind().delegate() 已弃用。这些功能在 1.12 或 2.2 中运行良好,没有警告消息,但在下一个版本和(当然)3.0 中将无法运行。

强烈建议使用.on()代替.bind().delegate()

http://blog.jquery.com/2016/01/08/jquery-2-2-and-1-12-released/ https://github.com/jquery/jquery/issues/2288